0

Whad the hell does "iterator" mean?

How does it work and where can we use it(and how?)?

18th Jan 2017, 6:37 PM
Nochains
Nochains - avatar
1 Respuesta
+ 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()); }
19th Jan 2017, 5:35 PM
Emmanuel Meena
Emmanuel Meena - avatar