Java TreeSet class
Java TreeSet class
- contains unique elements only like HashSet. The TreeSet class implements NavigableSet interface that extends the SortedSet interface.
- maintains ascending order.
Hierarchy of TreeSet class:
Example of TreeSet class:
- import java.util.*;
- class TestCollection11{
- public static void main(String args[]){
-
- TreeSet<String> al=new TreeSet<String>();
- al.add("Ravi");
- al.add("Vijay");
- al.add("Ravi");
- al.add("Ajay");
-
- Iterator<String> itr=al.iterator();
- while(itr.hasNext()){
- System.out.println(itr.next());
- }
- }
- }
No comments:
Post a Comment