I am writing a way to implement SortedSet in java.
SortedSet have the properties of Set interface plus feature of sorting in ascending order. It is by default provides elements in ascending order. It is very useful in such situation when we dont need duplicity and need sorted objects or elements.
Below is the example:
SortedSet mySortedSet = new TreeSet();
mySortedSet.add("John");
mySortedSet.add("Alex");
mySortedSet.add("Blue");
Iterator iterator = mySortedSet.iterator();
while (iterator.hasNext()) {
// Get element
Object object = iterator.next();
System.out.println(object.toString());
}
}
}
Output:
Alex
Blue
John
0 Comment(s)