java for each loop
int [] intArray = { 10, 20, 30, 40, 50 };
for( int value : intArray ) {
System.out.println( value );
}
3
1
// for each loop in java example
import java.util.*;
public class ForEachLoopExample
{
public static void main(String[] args)
{
int[] numbers = {2, 4, 6, 8, 10};
// for each loop
for(int n : numbers)
{
System.out.println(n);
}
}
}
Thank you!
1
0
4.25
4
for (String name : names) {
System.out.println(name);
}
Thank you!
4
0
3.88
8
List<String> someList = new ArrayList<String>();
// add "monkey", "donkey", "skeleton key" to someList
for (String item : someList) {
System.out.println(item);
}
Thank you!
8
0
4
6
//itemset contains variables of type <Data Type>
for(<Data Type> item : itemset) {
//loop
}
Thank you!
6
0
3.33
3
// definition eine Datenstruktur, hier ein Array mit 9 Werten
int[] array = new int[]{4, 8, 4, 2, 2, 1, 1, 5, 9};
// ForEach Schleife
for( int k: array )
{
System.out.println("k = "+k);
}
Thank you!
3
0
Are there any code examples left?
New code examples in category Java