Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SortedSet

 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a reference to a Set object (which naturally is not sorted) and I want to convert it to a SortedSet , do I have to iterate over all elements in the Set and copy them to the SortedSet(using a TreeSet)?Could there be a more efficient way of doing this?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really. Rather than writing the iteration yourself, you can use the TreeSet constructor that accepts a Collection as an argument; the TreeSet will then do that iteration itself (or use the addAll() method on an existing TreeSet.)
 
jeff mutonho
Ranch Hand
Posts: 271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic