Example usage for java.util ArrayList listIterator

List of usage examples for java.util ArrayList listIterator

Introduction

In this page you can find the example usage for java.util ArrayList listIterator.

Prototype

public ListIterator<E> listIterator() 

Source Link

Document

Returns a list iterator over the elements in this list (in proper sequence).

Usage

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.j  a  v a 2  s. c o  m
}

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());
    }//from w ww . j a va  2s  . com
}

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();
    listIterator.next();/* ww  w . ja  v  a  2s .c  o m*/
    listIterator.add("Added Element");
    for (String str : aList) {
        System.out.println(str);
    }
}

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());
    }/* w  ww  .j  a  v a2 s.  co  m*/
    while (listIterator.hasPrevious()) {
        System.out.println(listIterator.previous());
    }
}

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();
    listIterator.next();/*w ww  .ja  v  a  2s  . co m*/

    listIterator.set("100");
    for (String str : aList) {
        System.out.println(str);
    }
}

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();
    System.out.println("Previous: " + listIterator.previousIndex());
    System.out.println("Next: " + listIterator.nextIndex());

    // advance current position by one using next method
    listIterator.next();/*from  w ww . j  av a 2  s . c om*/
    System.out.println("Previous: " + listIterator.previousIndex());
    System.out.println("Next: " + listIterator.nextIndex());
}

From source file:Main.java

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

    arrlist.add(1);/*from www .  j a v a  2 s . com*/
    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<String> aList = new ArrayList<String>();
    aList.add("1");
    aList.add("2");
    aList.add("3");
    aList.add("4");
    aList.add("java2s.com");

    ListIterator<String> listIterator = aList.listIterator();
    listIterator.next();//from   ww w. j  a  v a 2 s  .c om
    listIterator.add("Added Element");
    for (String str : aList) {
        System.out.println(str);
    }
}

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<String> listIterator = aList.listIterator();
    System.out.println("Previous: " + listIterator.previousIndex());
    System.out.println("Next: " + listIterator.nextIndex());

    // advance current position by one using next method
    listIterator.next();// w w w  .  j a  v  a 2s  .  c  o m
    System.out.println("Previous: " + listIterator.previousIndex());
    System.out.println("Next: " + listIterator.nextIndex());
}

From source file:Main.java

public static void main(String[] args) {

    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1");
    arrayList.add("2");
    arrayList.add("3");
    arrayList.add("4");
    arrayList.add("5");

    ListIterator itr = arrayList.listIterator();
    System.out.println("in forward direction");
    while (itr.hasNext()) {
        System.out.println(itr.next());
    }/*from w w  w  .ja v a2s .  com*/

    System.out.println("in backward direction");
    while (itr.hasPrevious()) {
        System.out.println(itr.previous());
    }
}