Iterator ArrayList
Java 2016
package Demo22;
import java.util.*;
public class IteratorFailFastTest {
public void runIteratorAsList() {
List < String > listNames = Arrays.asList("Tom", "Joe", "Bill", "Dave", "John");
Iterator < String > iterator = listNames.iterator();
while (iterator.hasNext()) {
String nextName = iterator.next();
System.out.println(nextName);
}
}
public void runIteratorList() {
List < String > listNames = new ArrayList();
listNames.add("Tom");
listNames.add("Joe");
listNames.add("Bill");
listNames.add("Dave");
listNames.add("John");
Iterator < String > iterator = listNames.iterator();
while (iterator.hasNext()) {
String nextName = iterator.next();
System.out.println(nextName);
}
}
public static void main(String[] args) {
IteratorFailFastTest tester = new IteratorFailFastTest();
tester.runIteratorAsList();
tester.runIteratorList();
}
}
0 nhận xét:
Post a Comment