top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the major advantage of external iteration over internal iteration in java?

0 votes
490 views
What is the major advantage of external iteration over internal iteration in java?
posted Jan 19, 2018 by Jon Deck

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

External Iterators Definition(or Active Iterators) – With external iterators responsibility of iterating over the elements, and making sure that this iteration takes into account the total number of records, whether more records exist to be iterated and so on lies with the programmer.

Internal Iterators(or Passive Iterators) – Internal Iterators manage the iterations in the background. This leaves the programmer to just declaratively code what is meant to be done with the elements of the Collection, rather than managing the iteration and making sure that all the elements are processed one-by-one.

Advantage of internal iterators over external iterators:

  1. Improved code readability as its declarative in nature
  2. Concise code as multiple lines of code for external iterators is
    reduced to just one or two lines of code in case of internal
    iterators
  3. Simplified implementation/less defects as code written by programmer
    is very less, chances of bugs creeping into the iteration logic are
    not there.
answer Feb 5, 2018 by Ammy Jack
...