+ 1

What means “:” in java?

Eg: for( int a:b) { System.out.println(a); }

8th Jan 2018, 1:42 PM
Kaung Kyaw
Kaung Kyaw - avatar
4 odpowiedzi
+ 8
@Kuang Kyaw, please update your app to the latest version to get to that link. The enhanced for loop (sometimes called a "for each" loop) is used to traverse elements in arrays. The advantages are that it eliminates the possibility of bugs and makes the code easier to read. Example: int[ ] primes = {2, 3, 5, 7}; for (int t: primes) { System.out.println(t); } /* 2 3 5 7 */ The enhanced for loop declares a variable of a type compatible with the elements of the array being accessed. The variable will be available within the for block, and its value will be the same as the current array element. So, on each iteration of the loop, the variable t will be equal to the corresponding element in the array.
8th Jan 2018, 1:57 PM
Dev
Dev - avatar
+ 8
It's an enhanced for loop. You'll get it here: https://www.sololearn.com/learn/Java/2209/
8th Jan 2018, 1:47 PM
Dev
Dev - avatar
+ 1
I didn’t find! Please explain me
8th Jan 2018, 1:50 PM
Kaung Kyaw
Kaung Kyaw - avatar
+ 1
Thanks you! 🤩🤩
8th Jan 2018, 2:02 PM
Kaung Kyaw
Kaung Kyaw - avatar