I know the output is four one three two. Can any one explain how? Since there are five items, but only four are printed.
TreeSet map = new TreeSet();
map.add("one");
map.add("two");
map.add("three");
map.add("four");
map.add("one");
Iterator it = map.iterator();
while (it.hasNext() )
{
System.out.print( it.next() + " " );
}
TreeSet does not allow duplicate entries.
When it is accessed it will return elements in natural order (alphabetical order).
Refer:
http://docs.oracle.com/javase/6/docs/api/java/util/TreeSet.html