+ 3
For-each
How I use for-each loop?
3 Respostas
+ 3
public static void main(String[] args){
int[] array = {2, 5, 9, 3, 4};
for(int x: array){
System.out.println(x);
}
}
The output will be:
2
5
9
3
4
The variable x is taking the values in the array.
+ 3
Hi martin !
With java 8 specifications , java has added a new programming style of loop within Lists so just you have to check if ur JDK is grater or equal to 1.8 to use the below code :
public class ForEach{
public static void main(String [] args) {
List<Integer> array = new ArrayList<>();
array.add(1);
array.add(2);
array.add(3);
array.forEach(element -> {
System.out.println(element);
});
}}
// Output: 1
2
3
- 3
int v
for(a=0;a<v;a++)