Home » Java Programming » Objects and Collections

What will be the output of the program? 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() + " " ); }

Correct Answer: four one three two

Explanation:

TreeSet assures no duplicate entries; also, when it is accessed it will return elements in natural order, which typically means alphabetical.

← Previous Question Next Question→

More Questions from Objects and Collections

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion