import java.util.ArrayList;
import java.util.ListIterator;

class TestArrayList
{
    public static void main( String [ ] args )
    {
        ArrayList lst = new ArrayList( );
        lst.add( "2" );
        lst.add( "4" );
        
        ListIterator itr1 = lst.listIterator( 0 );
        System.out.print( "Forward: " );
        while( itr1.hasNext( ) )
            System.out.print( itr1.next( ) + " " );
        System.out.println( );    
            
        System.out.print( "Backward: " );
        while( itr1.hasPrevious( ) )
            System.out.print( itr1.previous( ) + " " );
        System.out.println( );    
        
        System.out.print( "Backward: " );
        ListIterator itr2 = lst.listIterator( lst.size( ) );
        while( itr2.hasPrevious( ) )
            System.out.print( itr2.previous( ) + " " );    
        System.out.println( );    
      
        ArrayList lst2 = new ArrayList( lst );  
        while( itr1.hasNext( ) )
        {
            Object x = itr1.next( );
            itr1.remove( );
            System.out.println( x );
        }
        
        ListIterator itr3 = lst2.listIterator( lst2.size( ) );
        while( itr3.hasPrevious( ) )
        {
            Object x = itr3.previous( );
            itr3.remove( );
            System.out.println( x );
        }
    }    
}
