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. List<String> list1 = new ArrayList<>();
  13. list1.add("foo");
  14. System.out.println("list1: " + list1 ); // foo
  15.  
  16. List<String> list2 = new ArrayList<>( list1 ) ;
  17. list1.clear();
  18. list2.add( "bar" );
  19. System.out.println( "list1: " +list1 ); // empty
  20. System.out.println( "list2: " +list2 ); // foo, bar
  21. }
  22. }
Success #stdin #stdout 0.11s 53860KB
stdin
Standard input is empty
stdout
list1: [foo]
list1: []
list2: [foo, bar]