File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes SortedSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "SortedSet" Watch "SortedSet" New topic
Author

SortedSet

jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
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

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.)


[Jess in Action][AskingGoodQuestions]
jeff mutonho
Ranch Hand

Joined: Apr 30, 2003
Posts: 271
Thanx
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SortedSet
 
Similar Threads
Can a set ever be ordered ?
how to easily sort the same TreeSet few times?
Why doesn't Collection Interface "set" have a get method like List?
Quession obout cellection
Getting closest element from a TreeSet