fork(3) 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. LocalDate today = LocalDate.now( ZoneId.of( "Africa/Tunis" ) ) ;
  16. List< LocalDate > dates = List.of(
  17. today.minusDays( 1 ) , // Yesterday
  18. today , // Today
  19. today.plusDays( 1 ) // Tomorrow
  20. );
  21.  
  22. System.out.println( "dates.toString(): " + dates );
  23.  
  24.  
  25. List< String > colors = new ArrayList<>( 4 ) ;
  26. colors.add ( "AliceBlue" ) ;
  27. colors.add ( "PapayaWhip" ) ;
  28. colors.add ( "Chartreuse" ) ;
  29. colors.add ( "DarkSlateGray" ) ;
  30. List< String > masterColors = List.copyOf( colors ) ; // Creates an unmodifiable list.
  31. //masterColors.remove( 3 ) ; // FAIL - COMPILER ERROR.
  32. colors.remove( 2 ) ; // SUCCEEDS.
  33.  
  34. System.out.println( "colors.toString(): " + colors ) ;
  35. System.out.println( "masterColors.toString(): " + masterColors ) ;
  36.  
  37. }
  38. }
Success #stdin #stdout 0.13s 37980KB
stdin
Standard input is empty
stdout
dates.toString(): [2020-02-02, 2020-02-03, 2020-02-04]
colors.toString(): [AliceBlue, PapayaWhip, DarkSlateGray]
masterColors.toString(): [AliceBlue, PapayaWhip, Chartreuse, DarkSlateGray]