Example usage for java.util ListIterator next

List of usage examples for java.util ListIterator next

Introduction

In this page you can find the example usage for java.util ListIterator next.

Prototype

E next();

Source Link

Document

Returns the next element in the list and advances the cursor position.

Usage

From source file:Main.java

public static void main(String[] args) {
    Vector<Integer> vec = new Vector<Integer>();

    vec.add(4);/*  w w w . j  av a  2 s .c o  m*/
    vec.add(3);
    vec.add(2);
    vec.add(1);

    System.out.println(vec);

    ListIterator<Integer> it = vec.listIterator(2);
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

From source file:UtilDemo3.java

public static void main(String[] args) {
    String[] coins = { "A", "B", "C", "D", "E" };

    List l = new ArrayList();
    for (int i = 0; i < coins.length; i++)
        l.add(coins[i]);/*ww w .j  a  v  a2s  . c om*/

    ListIterator liter = l.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());

    Collections.reverse(l);

    liter = l.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());
}

From source file:Main.java

public static void main(String[] args) {
    String[] coins = { "A", "B", "C", "D", "E" };

    List src = new LinkedList();
    for (int i = 0; i < coins.length; i++)
        src.add(coins[i]);// w  w w . j  a  v a  2 s. c o m

    List dst = new ArrayList();
    for (int i = 0; i < coins.length; i++)
        dst.add("");

    Collections.copy(dst, src);

    ListIterator liter = dst.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> aList = new ArrayList<String>();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    ListIterator listIterator = aList.listIterator();
    while (listIterator.hasNext()) {
        System.out.println(listIterator.next());
    }//  ww w .  ja v  a 2 s .c om
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> aList = new ArrayList<String>();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("java2s.com");

    ListIterator listIterator = aList.listIterator();
    while (listIterator.hasNext()) {
        System.out.println(listIterator.next());
    }//  w  ww .  jav a2s.c  o m
}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<Integer> arrlist = new ArrayList<Integer>();

    arrlist.add(1);/*  ww  w.  ja  v a 2s.  c  o m*/
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    ListIterator<Integer> iterator = arrlist.listIterator();
    while (iterator.hasNext()) {
        Integer i = iterator.next();
        iterator.remove();

    }
    System.out.println(arrlist);

}

From source file:Main.java

public static void main(String args[]) {
    ArrayList<Integer> arrlist = new ArrayList<Integer>();

    arrlist.add(1);//from w  w  w  .  j a  v  a2s. c  o m
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    ListIterator<Integer> iterator = arrlist.listIterator(2);
    while (iterator.hasNext()) {
        Integer i = iterator.next();
        iterator.remove();

    }
    System.out.println(arrlist);

}

From source file:MainClass.java

public static void main(String[] args) {
    String[] coins = { "A", "B", "C", "D", "E" };

    List src = new LinkedList();
    for (int i = 0; i < coins.length; i++)
        src.add(coins[i]);//from www .j  ava2 s.  co  m

    List dst = new ArrayList();
    for (int i = 0; i < coins.length; i++)
        dst.add("");

    Collections.copy(dst, src);

    ListIterator liter = dst.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());

    Collections.fill(src, "no coins");

    liter = src.listIterator();

    while (liter.hasNext())
        System.out.println(liter.next());
}

From source file:Main.java

public static void main(String[] args) {
    ArrayList<String> aList = new ArrayList<String>();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("5");

    ListIterator<String> listIterator = aList.listIterator();

    while (listIterator.hasNext()) {
        System.out.println(listIterator.next());
    }//www .j  a v  a  2s .  c o  m
    while (listIterator.hasPrevious()) {
        System.out.println(listIterator.previous());
    }
}

From source file:IteratorDemo.java

public static void main(String args[]) {
    ArrayList<String> al = new ArrayList<String>();

    al.add("C");// w  w  w.  j  a  va 2 s .c  om
    al.add("A");
    al.add("E");
    al.add("B");
    al.add("D");
    al.add("F");

    Iterator<String> itr = al.iterator();
    while (itr.hasNext()) {
        String element = itr.next();
        System.out.print(element + " ");
    }

    ListIterator<String> litr = al.listIterator();
    while (litr.hasNext()) {
        String element = litr.next();
        litr.set(element + "+");
    }

    itr = al.iterator();
    while (itr.hasNext()) {
        String element = itr.next();
        System.out.print(element + " ");
    }

    while (litr.hasPrevious()) {
        String element = litr.previous();
        System.out.print(element + " ");
    }
}