Saturday, January 28, 2017
Đọc dữ liệu từ ArrayList bằng Iterator trong Java Iterator ArrayList Java
Đọc dữ liệu từ ArrayList bằng Iterator trong Java Iterator ArrayList Java
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();
}
}
Available link for download