ArrayList练习:
package test19;import java.util.ArrayList;
import java.util.Iterator;public class ArrayListDemo {public static void main(String[] args){ArrayList<String> array = new ArrayList<String>();array.add("hello");array.add("world");array.add("java");for (String s:array){System.out.println(s);}Iterator<String> it = array.iterator();while(it.hasNext()){String s = it.next();System.out.println(s);}for (int i = 0;i<array.size();i++){String s = array.get(i);System.out.println(s);}}}
LinkedList练习:
package test19;import java.util.Iterator;
import java.util.LinkedList;public class LinkedListDemo {public static void main(String[] args){LinkedList<String> llst = new LinkedList<String>();llst.add("hello");llst.add("world");llst.add("java");for (String s:llst){System.out.println(s);}for (int i = 0;i<llst.size();i++){String s = llst.get(i);System.out.println(s);}Iterator<String> it = llst.listIterator();while(it.hasNext()){String s = it.next();System.out.println(s);}}
}