0
Whad the hell does "iterator" mean?
How does it work and where can we use it(and how?)?
1 Resposta
+ 2
looping in collection without keeping track of element of collection.
we use it when we want to retrieve one element after another without using loop . ( note with iterator object you can get value of each element of collection by just calling next() on each call you will get new value when exists.
//hasnext func return true when there are items in collection
//next return the current value each time when looping
ArrayList<String> collobject=new ArrayList<>();
collobject.add("java");
iterator iter=collobject.iterator();
while(iter.hasNext()){
System.out.println(iter.next());
}