/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { { ArrayList<String> sam; sam = new ArrayList<String>(); sam.add( "ben" ); sam.add( 0, "wil" ); sam.set( 1, "cat" ); sam.add( 1, "dog" ); sam.add( "pig" ); sam.remove(2); sam.remove(1); sam.add("one"); sam.add(0,"five"); sam.remove(1); sam.add( 0, "chair" ); for(int i = 0; i < sam.size(); i++) sam.remove( sam.size()-1 ); for( int i = 0; i < 4; i+=2 ) sam.add( i, "fun" ); } }
Standard input is empty
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]