List遍历的方法分为三种类型
1.for循环遍历 2.迭代器遍历 3.foreach循环遍历
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| public class TestList { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("布朗克斯"); list.add("布鲁克林"); list.add("曼哈顿"); list.add("皇后区"); list.add("斯塔滕岛"); for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } System.out.println("======================================"); Iterator iterator = list.iterator(); while (iterator.hasNext()){ String data = iterator.next().toString(); System.out.println(data); } System.out.println("======================================"); for (String data:list) { System.out.println(data); } } }
|