explain traversing through a collector using


Explain traversing through a collector using Iterator.

Ans. We can access each element in Collection by using Iterators regardless of how they are organized in collector. Iterator can be implemented a different way for each Collection. To use an iterator to traverse through the contents of a collection we do:

  • Obtain an iterator by calling collections iterator()method to the start of collection.
  • Set up a loop which makes a call to hasNext(). Have the loop iterate as long as hasNext()returns true.
  • Within loop, obtain every element by calling next().
  • remove() method is used to remove current element in iteration.

 

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: explain traversing through a collector using
Reference No:- TGS0355117

Expected delivery within 24 Hours