java 写一个迭代器 遍历List
时间: 2023-05-24 12:01:37 浏览: 113
Sure, here's an example of iterating over a List in Java using an Iterator:
```
List<String> list = new ArrayList<>();
list.add("apple");
list.add("banana");
list.add("orange");
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
String element = iterator.next();
System.out.println(element);
}
```
This will output:
```
apple
banana
orange
```
阅读全文