Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to sort a Set<Currency>?  RSS feed

 
Ranch Hand
Posts: 451
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: 5146
54
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
 
Dana Ucaed
Ranch Hand
Posts: 451
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: 5146
54
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: 61756
193
  • 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: 5146
54
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: 3002
105
  • 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: 451
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: 61756
193
  • 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!