If, there are two or more elements are same in a list(dvdList). I get different output at different time of execution. Is that how sorting algorithm work in collections?
Could you show us the comparator code? Could you show us sample data? Could you show us sample output? Etc...
Hi Henry,
Here is the Comparator code...
first output is:
[Raiders of the Lost Ark action Ford, Harrison , Patriot Games action Ford, Harrison , Caddy Shack comedy Murray, Bill , Lost in Translation comedy Murray, Bill , Donnie Darko sci-fi Gyllenhall,Jake , 2001 sci-fi ?? , Star Wars sci-fi Ford, Harrison ] second output is:
[Patriot Games action Ford, Harrison ,Raiders of the Lost Ark action Ford, Harrison , Caddy Shack comedy Murray, Bill , Lost in Translation comedy Murray, Bill , Donnie Darko sci-fi Gyllenhall,Jake , 2001 sci-fi ?? , Star Wars sci-fi Ford, Harrison ]
Thank you Saritha
Shiraz Choudhary
Greenhorn
Joined: Aug 20, 2008
Posts: 4
posted
0
Hi Saritha! I am not sure if i am right, but i am guessing that you are only sorting the collection just by the genre. The "toString()" method for "DVDInfo" object is this:
then the output you have is sorted by genre. Look at it again, genre is sorted.
The collection is not sorted by the title so the DVDInfo objects that has the same genre but different titles can switch their order but only within each other. You will not have comedy or Sci-fi come before action, no matter how many times you run the code.
It would be easy to answer your question if you write all of the code for this program. Like how you are sorting (compareTo or Compare method) the main method etc.
[ September 27, 2008: Message edited by: Shiraz Choudhary ] [ September 27, 2008: Message edited by: Shiraz Choudhary ]
SCJP 6.0
aslika bahini
Ranch Hand
Joined: Mar 03, 2007
Posts: 111
posted
0
Hi Shiraz Choudhary,
It would be easy to answer your question if you write all of the code for this program. Like how you are sorting (compareTo or Compare method) the main method etc
Here is the code... I think I am little confused. I get the same result when I execute this time. The result in book(pg 555) and mine is different. Thanks for the help.