Java For Each Loop Example

This loop will not check the condition, it will print each and every statement in the array.

Suppose you want each and every user detail from the database. And you don't know how many total no. user data present in the table.

Therefore, at that time you can use for each loop to retrieve detail of each and every user from the database.

public class ForEachLoop { public static void main(String[] args) { int[] value = {1,2,3,4}; for (int i : value) { System.out.println(i); } } }