forked from echoTheLiar/JavaCodeAcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIteratorClient.java
More file actions
28 lines (23 loc) · 592 Bytes
/
IteratorClient.java
File metadata and controls
28 lines (23 loc) · 592 Bytes
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
27
28
package designpattern.iterator;
/**
* 迭代器客户端
*
* @author liu yuning
*
*/
public class IteratorClient {
public static void main(String[] args) {
ConcreteAggregate<String> bus = new ConcreteAggregate<String>();
bus.setItems("大鸟");
bus.setItems("小菜");
bus.setItems("行李");
bus.setItems("老外");
bus.setItems("公交内部员工");
bus.setItems("小偷");
Iterator<String> iterator = new ConcreteIterator<String>(bus);
while (!iterator.isDone()) {
System.out.println(iterator.currentItem() + "请买票!");
iterator.next();
}
}
}