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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. ArrayList < String > list1 = new ArrayList() ;
  13. list1.add( "France" ) ;
  14. list1.add( "Spain" ) ;
  15.  
  16. ArrayList < String > list2 = new ArrayList( 10 ) ;
  17. list2.add( "Canada" ) ;
  18.  
  19. ArrayList < String > list3 = new ArrayList( list2 ) ; // Loaded with the contents of list2, the one element of "Canada".
  20. list3.add( "Mexico" ) ; // Adds a second element of "Mexico" after the starting element of "Canada".
  21.  
  22. System.out.println( "list1.toString() ➡️ " + list1 ) ;
  23. System.out.println( "list2.toString() ➡️ " + list2 ) ;
  24. System.out.println( "list3.toString() ➡️ " + list3 ) ;
  25. }
  26. }
Success #stdin #stdout 0.13s 55584KB
stdin
Standard input is empty
stdout
list1.toString() ➡️ [France, Spain]
list2.toString() ➡️ [Canada]
list3.toString() ➡️ [Canada, Mexico]