赞
踩
Iterable 迭代器只能迭代一次
- public class IterableTest {
-
-
- public static void main(String[] args) {
- List<String> list=new ArrayList<>();
- list.add("a");
- list.add("b");
- list.add("c");
- list.add("d");
- list.add("e");
-
- Iterator<String> iterator = list.iterator();
-
- while (iterator.hasNext()) {
- String next = iterator.next();
- System.out.println(next);
- }
- System.out.println("-------------------------------------");
- while (iterator.hasNext()) {
- String next = iterator.next();
- System.out.println(next);
- }
-
- }
- }
输出结果:
- a
- b
- c
- d
- e
- -------------------------------------
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。