0

Need a understanding on this

So in collections if we use for (i:j) print (i) what does it mean?

27th Feb 2021, 2:18 PM
Bugs-bunny
Bugs-bunny - avatar
5 odpowiedzi
+ 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); }
27th Feb 2021, 4:15 PM
A͢J
A͢J - avatar
+ 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);
1st Mar 2021, 11:52 AM
Wei Phyo Aung
Wei Phyo Aung - avatar
+ 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 }
27th Feb 2021, 4:08 PM
D_Stark
D_Stark - avatar
0
Bugs-bunny Is it Java? Can you give one more example?
27th Feb 2021, 3:08 PM
A͢J
A͢J - avatar
0
Yes . For (a:j) Print (a); Used it in for sorting using collections
27th Feb 2021, 3:11 PM
Bugs-bunny
Bugs-bunny - avatar