-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameRepo.java
More file actions
38 lines (31 loc) · 790 Bytes
/
Copy pathNameRepo.java
File metadata and controls
38 lines (31 loc) · 790 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
29
30
31
32
33
34
35
36
37
38
package iterator;
/**
* 具体的集合类
*/
public class NameRepo implements ContainerAggregate {
// 内部元素细节
private String names[] = {"john", "tiny", "bob", "marry"};
// 获取迭代器
@Override
public Iterator getIterator() {
return null;
}
// 内部类-具体迭代器,可以访问集合类内部细节names
private class NameIterator implements Iterator {
int index;
@Override
public boolean hasNext() {
if (index < names.length) {
return true;
}
return false;
}
@Override
public Object next() {
if (hasNext()) {
return names[index++];
}
return null;
}
}
}