-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaIterator.java
More file actions
52 lines (37 loc) · 1.09 KB
/
JavaIterator.java
File metadata and controls
52 lines (37 loc) · 1.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Dell
*/
import java.util.*;
public class JavaIterator {
public static Iterator myFun(ArrayList mylist){
Iterator itr = mylist.iterator();
while(itr.hasNext()){
Object element = itr.next();
if(element instanceof String)
// System.out.println("Iterator stopped at :: "+element);
break;
}
return itr;
}
public static void main(String[] args){
ArrayList mylist = new ArrayList();
mylist.add(1);
mylist.add(2);
mylist.add(3);
mylist.add("Hello");
mylist.add(5);
mylist.add(6);
mylist.add(7);
Iterator itr = myFun(mylist);
while(itr.hasNext()){
Object element1 = itr.next();
System.out.println(element1);
}
}
}