java list遍历的几种方法

List list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("orange");

for (int i = 0; i < list.size(); i++) {
    String element = list.get(i);
    System.out.println(element);
}

List list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("orange");

for (String element : list) {
    System.out.println(element);
}

List list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("orange");

Iterator iterator = list.iterator();
while (iterator.hasNext()) {
    String element = iterator.next();
    System.out.println(element);
}

你可能感兴趣的:(java,java,list,windows)