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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 274
    Comment on it

    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)

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: