package com.tutego.insel.util.list;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;

public class ListIteratorDemo
{
  public static void main( String[] args )
  {
    List<Object> list = new ArrayList<Object>();
    Collections.addAll( list, "b", "c", "d" );

    ListIterator<Object> it = list.listIterator();

    it.add( "a" );                     // Vorne anfügen
    System.out.println( list );        // [s, a, b, c, d]

    it.next();
    it.remove();
    System.out.println( list );        // [a, c, d]

    it.next();
    it.set( "i" );
    System.out.println( list );        // [a, i, d]

    it = list.listIterator( list.size()/2 - 1 );
    it.add( "l" );
    it.add( "v" );
    System.out.println( list );        // [l, v, a, i, d]
    
    it = list.listIterator( 1 );

    it.previous();                     // Eine Stelle nach vorne
    it.remove();
    System.out.println( list );        // [v, a, i, d]
  }
}
