fork download
  1.  
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class MySetWithCollection {
  8. public static void main(String a[]){
  9. List<String> li = new ArrayList<String>();
  10. li.add("one");
  11. li.add("two");
  12. li.add("three");
  13. li.add("four");
  14. System.out.println("List: "+li);
  15. //create a treeset with the list
  16. TreeSet<String> myset = new TreeSet<String>(li);
  17. System.out.println("Set: "+myset);
  18. }
  19. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
List: [one, two, three, four]
Set: [four, one, three, two]