Java Loops

java 8

Java forEach()

Java forEach() is a utility function to iterate over a Collection (list, set or map) or Stream. It performs the specified Consumer action on each item in the Collection.

Java ArrayList forEach()

ArrayList forEach() method iterate the list and performs the argument action for each element of the list until all elements have been processed.

Java Do-while

Java do-while loop executes the statements in do block, and then evaluates a condition in the while block to check whether to repeat the execution.

Java while Loop

The while loop in Java continually executes a block of statements until a particular condition evaluates to true, else the loop terminates.

Java For-each Loop

Since Java 1.5, the for-each loop or enhanced for loop is a concise way to iterate over the elements of an array and a Collection.

Java For Loop

Java for-loop statement is used to iterate over the arrays or collections using a counter variable that is incremented after each iteration.

Comparing Performance of Java Loops

This Java article compares the performance of an ArrayList iteration using simple for-loop, enhanced for-loop, list iterator and stream API.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.