- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJava Iterator.java
More file actions
Latest commit
36 lines (31 loc) · 850 Bytes
/
Copy pathJava Iterator.java
File metadata and controls
36 lines (31 loc) · 850 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
importjava.util.*;
publicclassMain{
staticIteratorfunc(ArrayListmylist){
Iteratorit=mylist.iterator();
while(it.hasNext()){
Objectelement =it.next();
if(elementinstanceofString)//Hints: use instanceof
break;
}
returnit;
}
@SuppressWarnings({ "unchecked" })
publicstaticvoidmain(String []args){
ArrayListmylist = newArrayList();
Scannersc = newScanner(System.in);
intn = sc.nextInt();
intm = sc.nextInt();
for(inti = 0;i<n;i++){
mylist.add(sc.nextInt());
}
mylist.add("###");
for(inti=0;i<m;i++){
mylist.add(sc.next());
}
Iteratorit=func(mylist);
while(it.hasNext()){
Objectelement = it.next();
System.out.println((String)element);
}
}
}