List of usage examples for java.util ListIterator hasPrevious
boolean hasPrevious();
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. ja va2 s . c om*/ }
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 ww w . jav a 2s.co 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;/*from w ww .j av a 2 s .c om*/ } System.out.println(list); }
From source file:Unsupported.java
public static void main(String[] args) { System.out.println(a);/* w w w . j ava 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 . j av a 2 s . c o m 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");//w w w . java2 s. co m 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 w w.j av a 2s . c o 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 ww . j a va 2 s . co m System.out.println("reverse direction"); while (itr.hasPrevious()) { System.out.println(itr.previous()); } }
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()); }/*w w w. j a va2 s . c o m*/ System.out.println("in backward direction"); while (itr.hasPrevious()) { System.out.println(itr.previous()); } }
From source file:MainClass.java
public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); al.add("C");/*from w ww .j ava 2 s.c om*/ al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); System.out.print("Original contents of al: "); Iterator<String> itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } System.out.println(); ListIterator<String> litr = al.listIterator(); while (litr.hasNext()) { String element = litr.next(); litr.set(element + "+"); } // Now, display the list backwards. System.out.print("Modified list backwards: "); while (litr.hasPrevious()) { String element = litr.previous(); System.out.print(element + " "); } }