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.Month ;
  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. Set< String > mySetOfStrings = new HashSet<>() ;
  15. mySetOfStrings.add( "dog" ) ;
  16. mySetOfStrings.add( "cat" ) ;
  17. mySetOfStrings.add( "bird" ) ;
  18.  
  19. int index = 0 ;
  20. String s = mySetOfStrings.toArray( new String[0] )[ index ] ;
  21. System.out.println( s ) ;
  22.  
  23. Set< Month > q1 = EnumSet.of( Month.MARCH , Month.JANUARY , Month.FEBRUARY ) ; // An `EnumSet` iterates in the order in which the enum objects were defined.
  24. Month m = q1.toArray( new Month[0] )[ 1 ] ; // Feb.
  25. System.out.println ( m ) ;
  26.  
  27.  
  28. }
  29. }
Success #stdin #stdout 0.08s 51708KB
stdin
Standard input is empty
stdout
cat
FEBRUARY