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 > original = List.of( "Zebra" , "Giraffe", "Bison", "Hippo", "Elephant" ) ;
  13. ArrayList< String > a1 = new ArrayList <> ( original ) ;
  14. ArrayList< String > a2 = new ArrayList <> ( original ) ;
  15. ArrayList< String > a3 = new ArrayList <> ( original ) ;
  16.  
  17. a1.subList( 0, 3 ).clear() ;
  18. a2.subList( 3, 5 ).clear() ;
  19. a3.subList( 2, 4 ).clear() ;
  20.  
  21. System.out.println( a1 );
  22. System.out.println( a2 );
  23. System.out.println( a3 );
  24.  
  25. }
  26. }
Success #stdin #stdout 0.08s 47024KB
stdin
Standard input is empty
stdout
[Hippo, Elephant]
[Zebra, Giraffe, Bison]
[Zebra, Giraffe, Elephant]