Example usage for java.util ListIterator previous

List of usage examples for java.util ListIterator previous

Introduction

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

Prototype

E previous();

Source Link

Document

Returns the previous element in the list and moves the cursor position backwards.

Usage

From source file:MainClass.java

public static void main(String[] a) {
    List list = new LinkedList();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator iter = list.listIterator(list.size());

    while (iter.hasPrevious()) {
        System.out.println(iter.previous());
    }/*w w w .  j  a v a2s .  c  o m*/

}

From source file:MainClass.java

public static void main(String[] a) {

    List list = new LinkedList();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator iter = list.listIterator(list.size());

    while (iter.hasPrevious()) {
        System.out.println(iter.previous());
        iter.add("a");
        break;/*from w w  w. j  ava2s . c  o  m*/
    }
    System.out.println(list);
}

From source file:Main.java

public static void main(String[] a) {
    List<String> list = new LinkedList<String>();
    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    ListIterator<String> iter = list.listIterator(list.size());

    while (iter.hasPrevious()) {
        System.out.println(iter.previous());
        iter.add("a");
        break;/* www . j a  v  a 2 s. co  m*/
    }
    System.out.println(list);
}

From source file:Unsupported.java

public static void main(String[] args) {
    System.out.println(a);/*www  .  java  2s  .  c o  m*/
    System.out.println(a2);
    System.out.println("a.contains(" + a.get(0) + ") = " + a.contains(a.get(0)));
    System.out.println("a.containsAll(a2) = " + a.containsAll(a2));
    System.out.println("a.isEmpty() = " + a.isEmpty());
    System.out.println("a.indexOf(" + a.get(5) + ") = " + a.indexOf(a.get(5)));
    // Traverse backwards:
    ListIterator lit = a.listIterator(a.size());
    while (lit.hasPrevious())
        System.out.print(lit.previous() + " ");
    System.out.println();
    // Set the elements to different values:
    for (int i = 0; i < a.size(); i++)
        a.set(i, "47");
    System.out.println(a);
    // Compiles, but won't run:
    lit.add("X"); // Unsupported operation
    a.clear(); // Unsupported
    a.add("eleven"); // Unsupported
    a.addAll(a2); // Unsupported
    a.retainAll(a2); // Unsupported
    a.remove(a.get(0)); // Unsupported
    a.removeAll(a2); // Unsupported
}

From source file:Employee.java

public static void main(String args[]) {
    LinkedList<Employee> phonelist = new LinkedList<Employee>();

    phonelist.add(new Employee("A", "1"));
    phonelist.add(new Employee("B", "2"));
    phonelist.add(new Employee("C", "3"));

    Iterator<Employee> itr = phonelist.iterator();

    Employee pe;/*from  w w w.ja  v a2s . c  om*/
    while (itr.hasNext()) {
        pe = itr.next();
        System.out.println(pe.name + ": " + pe.number);
    }
    ListIterator<Employee> litr = phonelist.listIterator(phonelist.size());

    while (litr.hasPrevious()) {
        pe = litr.previous();
        System.out.println(pe.name + ": " + pe.number);
    }
}

From source file:Main.java

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

    v.add("1");//from ww  w.ja  va2 s  .c om
    v.add("2");
    v.add("3");
    v.add("4");
    v.add("5");

    ListIterator itr = v.listIterator();
    while (itr.hasNext()) {
        System.out.println(itr.next());
    }
    while (itr.hasPrevious()) {
        System.out.println(itr.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();

    while (listIterator.hasNext()) {
        System.out.println(listIterator.next());
    }//from  w ww.  ja  va 2s . co m
    while (listIterator.hasPrevious()) {
        System.out.println(listIterator.previous());
    }
}

From source file:Main.java

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

    lList.add("1");
    lList.add("2");
    lList.add("3");
    lList.add("4");
    lList.add("5");

    ListIterator itr = lList.listIterator();
    System.out.println("forward direction");

    while (itr.hasNext()) {
        System.out.println(itr.next());
    }// w  w  w.  j  av  a  2  s .c  o  m
    System.out.println("reverse direction");
    while (itr.hasPrevious()) {
        System.out.println(itr.previous());
    }
}

From source file:MovingPlanets.java

public static void main(String args[]) {
    String names[] = { "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto" };
    List planets = new ArrayList();
    for (int i = 0, n = names.length; i < n; i++) {
        planets.add(names[i]);/*  w w w  . j  ava  2  s .c om*/
    }
    ListIterator lit = planets.listIterator();
    String s;
    lit.next();
    lit.next();
    s = (String) lit.next();
    lit.remove();
    lit.next();
    lit.next();
    lit.next();
    lit.add(s);
    lit.next(); // Gets back just added
    lit.previous();
    lit.previous();
    s = (String) lit.previous();
    lit.remove();
    lit.next();
    lit.next();
    lit.add(s);
    Iterator it = planets.iterator();
    while (it.hasNext()) {
        System.out.println(it.next());
    }
}

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());
    }/*ww w  . j a  v a2s  .  c  o  m*/

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