0
Need a understanding on this
So in collections if we use for (i:j) print (i) what does it mean?
5 Respuestas
+ 2
Bugs-bunny
That's called foreach loop where j should be collection and a should be any type of data like (string, int, double) depends on your collection type.
for example
int[] arr = {1, 2, 4};
for (int k : arr) {
System.out.println (k);
}
+ 4
It is called enhanced for loop.
You can use with array and collections . Here is eg...
int a[] = {1,2,3,4};
for(int i : a)
System.out.print(i);
+ 2
Collection and enhanced for loop are different things but can be used together to cycle through your collection of objects.
for(type var: c){
do somthing with var }
0
Bugs-bunny
Is it Java? Can you give one more example?
0
Yes . For (a:j)
Print (a);
Used it in for sorting using collections