forked from daveagp/java_visualize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestIter.java
More file actions
41 lines (41 loc) · 845 Bytes
/
TestIter.java
File metadata and controls
41 lines (41 loc) · 845 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
39
40
41
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
class Int {
int val;
Int(int n) { val = n; }
int plusPlus() { return val++; }
int getVal() {return val; }
}
public class TestIter {
static void display(List<Int> v) {
Iterator<Int> e = v.iterator();
Int s;
while(e.hasNext()){
s = e.next();
System.out.println(" "+ s.getVal());
}
}
static void incrementI(List<Int> v){
for(Int s : v){
s.plusPlus();
}
}
public static void main(String argv[]) {
List<Int> n = new Vector<Int>();
for(int i = 0; i < 10 ; i++) {
n.add(new Int(i));
}
Iterator<Int> e = n.iterator();
Int s;
while (e.hasNext()) {
s = e.next();
s.plusPlus();
}
System.out.println("Apres initialisation:");
display(n);
incrementI(n);
System.out.println("Apres increment par iterateur:");
display(n);
}
}