List of usage examples for java.util List listIterator
ListIterator<E> listIterator();
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]);/* w w w . jav a 2 s . 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[] 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 . ja v a2 s . com }
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()); }//w ww .ja v a2 s. com }
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]);/*from w w w . j a va 2 s .c om*/ 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: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 w ww . j a v a2 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: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 w w w .java 2s . 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()); 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) { String[] coins = { "A", "B", "C", "D", "E" }; List src = new LinkedList(); for (int i = 0; i < coins.length; i++) { src.add(coins[i]);//from w w w . j a va2 s . c om } System.out.println(src); Collections.fill(src, "java2s.com"); Iterator liter = src.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); }
From source file:Employee.java
public static void main(String[] args) { String[] names = { "A", "B", "C", "D" }; double[] salaries = { 2.0, 5.0, 6.0, 4.0 }; List l = new ArrayList(); for (int i = 0; i < names.length; i++) l.add(new Employee(names[i], salaries[i])); Collections.sort(l);//ww w . java 2 s . co m ListIterator liter = l.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); Collections.sort(l, new Employee.SalaryComparator()); liter = l.listIterator(); while (liter.hasNext()) System.out.println(liter.next()); }
From source file:Main.java
public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Oracle"); list.add("SQL"); list.add("CSS"); list.add("XML"); System.out.println("List: " + list); // Get the list iterator ListIterator<String> iterator = list.listIterator(); while (iterator.hasNext()) { int index = iterator.nextIndex(); String element = iterator.next(); System.out.println("Index=" + index + ", Element=" + element); }//from w w w. j a v a 2 s. co m // Reuse the iterator to iterate from the end to the beginning while (iterator.hasPrevious()) { int index = iterator.previousIndex(); String element = iterator.previous(); System.out.println("Index=" + index + ", Element=" + element); } }
From source file:LinkedListTest.java
public static void main(String[] args) { List<String> a = new LinkedList<String>(); a.add("Amy"); a.add("Carl"); a.add("Erica"); List<String> b = new LinkedList<String>(); b.add("Bob"); b.add("Doug"); b.add("Frances"); b.add("Gloria"); // merge the words from b into a ListIterator<String> aIter = a.listIterator(); Iterator<String> bIter = b.iterator(); while (bIter.hasNext()) { if (aIter.hasNext()) aIter.next();/*w w w .ja va 2 s . co m*/ aIter.add(bIter.next()); } System.out.println(a); // remove every second word from b bIter = b.iterator(); while (bIter.hasNext()) { bIter.next(); // skip one element if (bIter.hasNext()) { bIter.next(); // skip next element bIter.remove(); // remove that element } } System.out.println(b); // bulk operation: remove all words in b from a a.removeAll(b); System.out.println(a); }