Sep 23

The TreeSet class maintains its elements in order.


Set<String> set = new TreeSet<String>();
set.add("one");
set.add("two");
set.add("three");

for (String s : set)
{
   System.out.println(s);
}

// Output will be (as String's are sorted alpabetically):
// one
// three
// two 

written by objects \\ tags: ,


Leave a Reply

You must be logged in to post a comment.