javase-常用三种遍历方法

javase-常用三种遍历方法
 import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class Bianli {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
list.add("add");
list.add("bdd");
list.add("cdd");
// 三种遍历方式 for();for()增强;iterator
for (int i = 0; i < list.size(); i++) {
String s = list.get(i);
System.out.println(s);
}
for (String string : list) {
System.out.println(string);
}
Iterator<String> iterator = list.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
}
上一篇:There is no tracking information for the current branch


下一篇:flutter - 01 基础介绍以及ListView