TreeSet in java

by rajesh 2009-12-30 16:51:41

TreeSet stores objects in a sorted manner. TreeSet stores its elements automatically in a sorted tree structure.

That is if you add "a","z","b" in a tree set and then loop through it, it will be in the order "a","b","z"

Example :

TreeSet ts = new TreeSet();
ts.add("a");
ts.add("z");
ts.add("b");

Iterator it =ts.iterator();
while(it.hasNext()){
System.out.println(it.next());
}



Output:

a
b
z


Tagged in:

1367
like
0
dislike
0
mail
flag

You must LOGIN to add comments