I can iterate in array using Pythons for loops as
arr = []
for e in arr:
do smth. with each element
Does java has similar loop? If I will split the string in Java like this:
temp = str.split(delimiter);
Will I have array which can be looped with “for … in…” similar statement?
There is the
foreach“statement”:It works with arrays and all kinds of Collections as well (Sets, Lists, Maps), and in general for any class
Xwhich implementsIterable<X>, ie,Iterableof itself (which means you can write a class to use in a foreach statement, which is nice).So, you could write directly:
as
.split()returns an array, which is directly useable with a foreach statement. That is, if you don’t need another variable to hold the array index for whatever reason.