Skip to main content
added 112 characters in body
Source Link
candied_orange
  • 114.6k
  • 27
  • 222
  • 352

Consider TreeSet.

From javatpoint.com : treeset

import java.util.*;   

class TestCollection11{   

     public static void main(String args[]) {   

          //Creating and adding elements  
          TreeSet<String> al=newal = new TreeSet<String>();  
          al.add("Ravi");  
          al.add("Vijay");  
          al.add("Ravi");  
          al.add("Ajay");   

          //Traversing elements  
          Iterator<String> itr=alitr = al.iterator();  
          while( itr.hasNext() ) {  
               System.out.println(itr.next());  
          }  
     }  
}  

outputs

Ajay
Ravi
Vijay

Indeed, choosing the best data structure makes life easier.

Consider TreeSet.

From javatpoint.com : treeset

import java.util.*;  
class TestCollection11{  
 public static void main(String args[]){  
  //Creating and adding elements  
  TreeSet<String> al=new TreeSet<String>();  
  al.add("Ravi");  
  al.add("Vijay");  
  al.add("Ravi");  
  al.add("Ajay");  
  //Traversing elements  
  Iterator<String> itr=al.iterator();  
  while(itr.hasNext()){  
   System.out.println(itr.next());  
  }  
 }  
}  

outputs

Ajay
Ravi
Vijay

Indeed, choosing the best data structure makes life easier.

Consider TreeSet.

From javatpoint.com : treeset

import java.util.*;   

class TestCollection11{   

     public static void main(String args[]) {   

          //Creating and adding elements  
          TreeSet<String> al = new TreeSet<String>();  
          al.add("Ravi");  
          al.add("Vijay");  
          al.add("Ravi");  
          al.add("Ajay");   

          //Traversing elements  
          Iterator<String> itr = al.iterator();  
          while( itr.hasNext() ) {  
               System.out.println(itr.next());  
          }  
     }  
}  

outputs

Ajay
Ravi
Vijay

Indeed, choosing the best data structure makes life easier.

Source Link
candied_orange
  • 114.6k
  • 27
  • 222
  • 352

Consider TreeSet.

From javatpoint.com : treeset

import java.util.*;  
class TestCollection11{  
 public static void main(String args[]){  
  //Creating and adding elements  
  TreeSet<String> al=new TreeSet<String>();  
  al.add("Ravi");  
  al.add("Vijay");  
  al.add("Ravi");  
  al.add("Ajay");  
  //Traversing elements  
  Iterator<String> itr=al.iterator();  
  while(itr.hasNext()){  
   System.out.println(itr.next());  
  }  
 }  
}  

outputs

Ajay
Ravi
Vijay

Indeed, choosing the best data structure makes life easier.