List of usage examples for java.util ListIterator next
E 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("java2s.com"); ListIterator<String> listIterator = aList.listIterator(); listIterator.next(); listIterator.add("Added Element"); for (String str : aList) { System.out.println(str);/*from www.j a v a 2 s. co 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("5"); ListIterator<String> listIterator = aList.listIterator(); listIterator.next(); listIterator.add("Added Element"); for (String str : aList) { System.out.println(str);/* www. j a 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("5"); ListIterator<String> listIterator = aList.listIterator(); listIterator.next(); listIterator.set("100"); for (String str : aList) { System.out.println(str);/*from w w w. java 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("5"); // Get an object of ListIterator using listIterator() method ListIterator listIterator = aList.listIterator(); listIterator.next(); listIterator.next();/* w w w .ja v a 2 s . c o m*/ // remove element returned by last next method listIterator.remove(); for (String str : aList) { System.out.println(str); } }
From source file:ListExampleV1.java
public static void main(String args[]) { ListExampleV1 listExample = new ListExampleV1(); listExample.createLists();//from ww w. ja v a 2 s . c om uniqueList.add("Value1"); uniqueList.add("Value1"); System.err.println(uniqueList); // should contain only one element cursorList.add("Element1"); cursorList.add("Element2"); cursorList.add("Element3"); ListIterator iterator = cursorList.listIterator(); iterator.next(); // cursor now between 0th and 1st element iterator.add("Element2.5"); // adds this between 0th and 1st element System.err.println(cursorList); // modification done to the iterator are visible in the list }
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]);//from www. j ava2 s . c o m } 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[] a) { List<String> list = new LinkedList<String>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); ListIterator iter = list.listIterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/*from w ww . ja v a 2 s . c o m*/ }
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 iter = list.listIterator(1); while (iter.hasNext()) { System.out.println(iter.next()); }/*from w w w .j av a 2s.co m*/ }
From source file:Main.java
public static void main(String[] args) { Vector<String> v = new Vector<String>(); v.add("1");/*from www .j a v a2 s . com*/ 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[] a) { List list = new LinkedList(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); ListIterator iter = list.listIterator(); while (iter.hasNext()) { System.out.println(iter.next()); }/*from w w w . j ava 2 s . c o m*/ }