fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10.  
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Set<String> a = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
  14. SortedSet<String> b = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
  15. populate(a);
  16. show(a, "Original a");
  17. populate(b);
  18. show(b, "Original b");
  19. Set<String> copyA = new TreeSet<String>(a);
  20. show(copyA, "Copy of a");
  21. Set<String> copyB = new TreeSet<String>(b);
  22. show(copyB, "Copy of b");
  23. }
  24. static void populate(Set<String> s) {
  25. s.add("A");
  26. s.add("aa");
  27. s.add("B");
  28. s.add("bb");
  29. }
  30. static void show(Set<String> s, String name) {
  31. System.out.println("============ "+name+" ==========");
  32. for (String t : s) {
  33. System.out.println(t);
  34. }
  35. }
  36. }
Success #stdin #stdout 0.07s 3359744KB
stdin
Standard input is empty
stdout
============ Original a ==========
A
aa
B
bb
============ Original b ==========
A
aa
B
bb
============ Copy of a ==========
A
B
aa
bb
============ Copy of b ==========
A
aa
B
bb