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. import java.time.* ;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14.  
  15. Set< String > names = new TreeSet<> () ;
  16. names.add( "Carol" ) ;
  17. names.add( "Alice" ) ;
  18. names.add( "Bob" ) ;
  19. System.out.println( "names.toString(): " + names ) ;
  20.  
  21.  
  22. Set< DayOfWeek > weekend = EnumSet.of( DayOfWeek.SUNDAY , DayOfWeek.SATURDAY ) ;
  23. System.out.println("weekend.toString(): " + weekend ) ;
  24.  
  25. Set< String > colors = new LinkedHashSet<> () ;
  26. String peachPuff = "PeachPuff" ;
  27. colors.add( "CornflowerBlue" ) ;
  28. colors.add( peachPuff ) ;
  29. colors.add( "DarkSlateGray" ) ;
  30. colors.add( peachPuff ) ; // Adding repeatedly. Original insertion order maintained.
  31. System.out.println( "colors.toString(): " + colors ) ;
  32.  
  33. }
  34. }
Success #stdin #stdout 0.15s 36872KB
stdin
Standard input is empty
stdout
names.toString(): [Alice, Bob, Carol]
weekend.toString(): [SATURDAY, SUNDAY]
colors.toString(): [CornflowerBlue, PeachPuff, DarkSlateGray]