wood burning stoves 2.0*
The moose likes Java in General and the fly likes Sorting wih Comparator dont work ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sorting wih Comparator dont work ?" Watch "Sorting wih Comparator dont work ?" New topic
Author

Sorting wih Comparator dont work ?

Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
I have a class that sorts with comprator, but i dosent work !

Any good ideas, look at my code ?

Is there a better way to sort my list with objects ?

Daesung Park
Ranch Hand

Joined: Mar 22, 2007
Posts: 68
At a glance, creating a new instance in line 60 is problematic.

There are many ways to implement it correctly.
One solutin is to remove "implements Comparator" from TodaysHighAndLowBackingBean, and


Daesung Park

BLOG
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Daesung Park wrote:At a glance, creating a new instance in line 60 is problematic.

Although it is unnecessary, it shouldn't create any problems. And replacing it with will work just as fine.

Frank, what is the value of navToDay1 and navToDay2? Are you sure those values are correct?

You might also want to consider using


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
Arrays.sort(fundArray, this); i will try this monday when i back on work....

The value are doubles and contains in the range -8.00 and 10.00

I get a List back in the fundDao.getAllFunds(), i dont want to implement the Comparable in fundDao.....

Is there a more effective way to do this, in sted off looping true the list, and put it into a Array and sort the Array ?



Frank

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Frank Jacobsen wrote:Is there a more effective way to do this, in sted off looping true the list, and put it into a Array and sort the Array ?

I'm not sure what this question really means. There's Collections.sort(List, Comparator) which sorts a List -- so if you used that, you wouldn't have to copy the List to an array. You could just sort it in place. Or there's List.toArray() which produces an array from a List -- so if you used that, you wouldn't have to write your own code to copy the List to an array.
Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
So you mean that this will work:

this is implementing Comparator

this.funds is a list.

// see the above code



Frank
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

It should work. Of course you would have to change your method to return a List instead of an array of Funds.
Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
Thanks a LOT
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sorting wih Comparator dont work ?
 
Similar Threads
Sorting Table Columns
Sorting by 3 variables dynamically in arrayList
comparator example needed
Sorting Collection
Two threads of same class instance to wait separately