The enhanced for loop you use :
for(int element : array)
element = 10;
In java we have references referencing an object. At a time one reference can reference to only one object. If it is made to reference another object then it losses the reference to the previous one.
When you use = then you make element to reference another value i.e 10.
Here element is of type int, which is primitive type. Even if
it was an Integer then also Integer being immutable you would
have not been able to make any modifications in the object as
modifications always would have resulted in a separate object.
If it would have been the case as below for some Custom class say Student.java
For some List<Student> students.
for(Student std : students){
std.setName("eureka");
}
Now iterating the list and printing the name of each student would have
resulted in printing eureka for each student. But note that even in this case use of = would have again produced same result as you are getting now (as again you would have referenced the variable to different object, it would no longer reference to the original object of the list).