Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write "for x in list" in Java?

I was wondering how to express a certain type of for loop in Java.

In Python I would use:

for x in lst1:
       return 10

How would I do this in Java?

I know for the range for-loops, I use
for(int i=0; i<100; j++) {
   return "asdf"
}

I just want to know how to do the other type of loop

like image 891
Jon Anderson Avatar asked Jan 25 '13 23:01

Jon Anderson


1 Answers

int[] myints = {1, 2, 3, 4, 5};
for(int i : myints) {
    System.out.println(i);
}
like image 73
Eric Avatar answered Oct 04 '22 01:10

Eric