+ 1
What means â:â in java?
Eg: for( int a:b) { System.out.println(a); }
4 Answers
+ 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.
+ 8
It's an enhanced for loop. You'll get it here:
https://www.sololearn.com/learn/Java/2209/
+ 1
I didnât find! Please explain me
+ 1
Thanks you! đ€©đ€©