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> sam;
  13. sam = new ArrayList<String>();
  14. sam.add( "ben" );
  15. sam.add( 0, "wil" );
  16. sam.set( 1, "cat" );
  17. sam.add( 1, "dog" );
  18. sam.add( "pig" );
  19. sam.remove(2);
  20. System.out.println( sam.get(0) ); // LINE 1
  21. System.out.println( sam.get(2) ); // LINE 2
  22. System.out.println( sam.set(1, "up") ); // LINE 3
  23. System.out.println( sam.indexOf("ben")); // LINE 4
  24. System.out.println( sam.contains("sam")); // LINE 5
  25. System.out.println( sam ); // LINE 6
  26. sam.remove(1);
  27. System.out.println( sam ); // LINE 7
  28. sam.add("one");
  29. System.out.println( sam ); // LINE 8
  30. sam.add(0,"five");
  31. System.out.println( sam ); // LINE 9
  32. sam.remove(1);
  33. System.out.println( sam ); // LINE 10
  34. sam.add( 0, "chair" );
  35. System.out.println( sam ); // LINE 11
  36. for(int i = 0; i < sam.size(); i++)
  37. System.out.print( sam.get( i ) + " " ); // LINE 12
  38. System.out.println();
  39. sam.remove( sam.size()-1 );
  40. System.out.println( sam ); // LINE 13
  41. for( int i = 0; i < 4; i+=2 )
  42. sam.add( i, "fun" );
  43. System.out.println( sam ); // LINE 14
  44. }
  45. }
Success #stdin #stdout 0.11s 55436KB
stdin
Standard input is empty
stdout
wil
pig
dog
-1
false
[wil, up, pig]
[wil, pig]
[wil, pig, one]
[five, wil, pig, one]
[five, pig, one]
[chair, five, pig, one]
chair five pig one 
[chair, five, pig]
[fun, chair, fun, five, pig]