Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • TreeSet in Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 306
    Comment on it

    TreeSet class is the class that implements NavigableSet interface and NavaigableSet extends SortedSet which extends Set.

    TreeSet contains unique elements.
    Another important and powerful property is that it maintains ascending order.
    To use Tree set we have to import java.util.* package first.

    This is simplest way to implement Treeset

    TreeSet treeSet = new treeSet(); 
    treeSet.add(A java); 
    treeSet.add(D java); 
    treeSet.add(C java); 
    treeSet.add(B java); 
    Iterator iterator = treeSet.iterator(); 
    While(iterator.hasNext()){ 
    System.out.println(iterator.next()); 
    } 
    Now check the output: 
    A java 
    B java 
    C java 
    D java 

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: