Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
I understand what an iterator is, how do I implement the concept?

1 Answer

0 votes
by (11.3k points)

The following is the methodology to implement iterators in JAVA:

  • Call the collection's iterator() method to get to the start of the Collection that you want to iterate upon. 
  • Use a loop to iterate upon the collection while the hasNext() is true.
  • To get to the next element of the iterator and change the iterator pointer, use the next() function. 
    

If you want to understand the proper hands-on method to implement an iterator with a real project, you should look up this topic online or watch a good java tutorial

Related questions

0 votes
1 answer
asked Feb 13, 2020 in Java by angadmishra (6.5k points)
0 votes
1 answer
0 votes
1 answer
asked Feb 19, 2020 in Java by angadmishra (6.5k points)
0 votes
1 answer
asked Feb 18, 2020 in Java by angadmishra (6.5k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...