• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to sort a Set<Currency>?  RSS feed

 
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I discovered Currency class and the getAvailableCurrencies() method.

I want to display currency code in alphabetical order.

I don't know what I am missing.




The class Currency didn't implement Comparator interface.

Any hint would be appreciated.


 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
should be
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I don't have list variable, how can sort setC ?
 
Carey Brown
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dana Ucaed wrote:If I don't have list variable, how can sort setC ?

Yes you do. See line 9.
 
Marshal
Posts: 56608
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way to do it is to put all the elements from that List into a SortedList; you will still need the Comparator.
Why didn't you write the Comparator as a λ expression?
 
Carey Brown
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a "SortedList" in the JavaDocs for Java 8. There is a SortedSet and a SortedMap though.
 
Master Rancher
Posts: 2045
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think Campbell meant something like

Campbell Ritchie wrote:Why didn't you write the Comparator as a λ expression?

Dana is still on java 7.
 
Dana Ucaed
Ranch Hand
Posts: 406
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, Piet I am working on Java 7.

 
Campbell Ritchie
Marshal
Posts: 56608
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:I don't see a "SortedList" in the JavaDocs for Java 8. . . .
Damn! My spelling is getting worse and worse. Sorry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!