List of usage examples for java.util ArrayList iterator
public Iterator<E> iterator()
From source file:de.netallied.functionblock.converter.java2java.util.Directory.java
public static void main(String[] params) { File temp = new File("C:\\Temp"); ArrayList list = Directory.getAll(temp, true); Iterator it = list.iterator(); while (it.hasNext()) { System.out.println(((File) (it.next())).getAbsolutePath()); }//from w w w . jav a2s . co m System.out.println("Number of Files: " + list.size()); }
From source file:OldStyle.java
public static void main(String args[]) { ArrayList list = new ArrayList(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); Iterator itr = list.iterator(); while (itr.hasNext()) { String str = (String) itr.next(); // explicit cast needed here. System.out.println(str + " is " + str.length() + " chars long."); }//from ww w . java 2s .c o m }
From source file:MainClass.java
public static void main(String[] a) { ArrayList<String> nums = new ArrayList<String>(); nums.add("O"); nums.add("Two"); nums.add("Three"); nums.add("Four"); String s;/*from w w w. ja v a 2s. c o m*/ Iterator e = nums.iterator(); while (e.hasNext()) { s = (String) e.next(); System.out.println(s); } }
From source file:NewStyle.java
public static void main(String args[]) { ArrayList<String> list = new ArrayList<String>(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); Iterator<String> itr = list.iterator(); while (itr.hasNext()) { String str = itr.next(); // no cast needed System.out.println(str + " is " + str.length() + " chars long."); }/* w w w. j av a2 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"); Iterator itr = aList.iterator(); // iterate through the ArrayList values using Iterator's hasNext and next methods while (itr.hasNext()) { System.out.println(itr.next()); }// w w w . j av a 2 s . c o m }
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 a2 s. c o m*/ arrlist.add(2); arrlist.add(3); arrlist.add(4); arrlist.add(5); Iterator<Integer> iterator = arrlist.iterator(); while (iterator.hasNext()) { Integer i = iterator.next(); System.out.println(i); } }
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"); Iterator itr = arrayList.iterator(); while (itr.hasNext()) { System.out.println(itr.next()); }/* w w w . j a v a2 s. c o m*/ }
From source file:ArrayListGenericDemo.java
public static void main(String[] args) { ArrayList<String> data = new ArrayList<String>(); data.add("hello"); data.add("goodbye"); // data.add(new Date()); This won't compile! Iterator<String> it = data.iterator(); while (it.hasNext()) { String s = it.next();//w w w . j a v a 2s .c o m System.out.println(s); } }
From source file:IteratorDemo.java
public static void main(String args[]) { ArrayList<String> al = new ArrayList<String>(); al.add("C");/*from w w w. j a va 2s . c om*/ al.add("A"); al.add("E"); al.add("B"); al.add("D"); al.add("F"); Iterator<String> itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } ListIterator<String> litr = al.listIterator(); while (litr.hasNext()) { String element = litr.next(); litr.set(element + "+"); } itr = al.iterator(); while (itr.hasNext()) { String element = itr.next(); System.out.print(element + " "); } while (litr.hasPrevious()) { String element = litr.previous(); System.out.print(element + " "); } }
From source file:NewStyle.java
public static void main(String args[]) { // Now, list holds references of type String. ArrayList<String> list = new ArrayList<String>(); list.add("one"); list.add("two"); list.add("three"); list.add("four"); // Notice that Iterator is also generic. Iterator<String> itr = list.iterator(); // The following statement will now cause a compile-time eror. // Iterator<Integer> itr = list.iterator(); // Error! while (itr.hasNext()) { String str = itr.next(); // no cast needed // Now, the following line is a compile-time, // rather than runtime, error. // Integer i = itr.next(); // this won't compile System.out.println(str + " is " + str.length() + " chars long."); }/*from w ww . ja v a 2s . c o m*/ }