Computer Science, asked by TbiaSamishta, 1 year ago

What are the two ways to iterate the elements of a collection?

Answers

Answered by janhavi5350
2

Iteration is one of the basic operations carried on a collection. Basically, an iteration takes elements from a collection one after another, from the first element to the last one.

For example, you may want to go through all students in a class to print their names or to find who have high scores in the recent exam. Or you may want to traverse through a list of numbers in order to calculate the sum and average. Such kinds of operations are very common in programming.

The Java programming language provides four methods for iterating over collections, including for loops, iterator and for Each (since Java 8).


BHERE: mark as brainliestt.........plz
Answered by aqibkincsem
0

Using Iterator is still very popular way to iterate over collections, mainly due to addtional methods it provides to manipulate the collection elements.

It uses the standard for loop invented in the early 1970s in the C language. Traditional for loop is most appropriate when dealing with indexed collections such as list.

Similar questions