for each char in string java code example
Example 1: iterate over string java
String str = "hello";
for (char c : str.toCharArray())
//process c
Example 2: java foreach char
for (char ch: "xyz".toCharArray()) {
System.out.println(ch);
}
String str = "hello";
for (char c : str.toCharArray())
//process c
for (char ch: "xyz".toCharArray()) {
System.out.println(ch);
}