• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting wih Comparator dont work ?

 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Frank Jacobsen
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you mean that this will work:

this is implementing Comparator

this.funds is a list.

// see the above code



Frank
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a LOT
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic