foreach string java code example
Example 1: java foreach char
for (char ch: "xyz".toCharArray()) {
System.out.println(ch);
}
Example 2: lopp array java
For(<DataType of array/List><Temp variable name> : <Array/List to be iterated>){
System.out.println();
//Any other operation can be done with this temp variable.
}
Example 3: for each loop string java
String s = "xyz"
for (char ch: s.toCharArray()) {
System.out.println(ch);
}