• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to sort a Set<Currency>?  RSS feed

 
Ranch Hand
Posts: 442
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.


 
Bartender
Posts: 4531
50
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: 442
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
Bartender
Posts: 4531
50
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: 59762
188
  • 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
Bartender
Posts: 4531
50
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: 2758
93
  • 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: 442
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: 59762
188
  • 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!