I will explain some difference between for and for each loop in java..hope it will somewhat clarify your doubt.
Well both are looping and syntax for both..
For(datatype variable: array)
Obviously we can set the initial value and also final value in for loop and apply some conditions also possible..
But in foreach loop we can't set anything.it will process all the values in array or collection.
Consider the following example,
Public static void main(String args)
System.out.println("for loop output");
System.out.println("foreach loop output");
Output will be like this,
for loop output
So, when we want to deal with all elements in array it is better to use foreach loop..
And when we want to deal with some values in array it is better to use for loop...
:More reference :
Find time complexities among for and foreach explained here :