iterate each char in string in java code example
Example 1: iterate each char in string in java
class Main {
public static void main(String[] args) {
// create a string
String name = "Programiz";
System.out.println("Characters in string \"" + name + "\":");
// loop through each element using for-each loop
for(char c : name.toCharArray()) {
// access each character
System.out.print(c + ", ");
}
}
}
Example 2: iterate each char in string in java
class Main {
public static void main(String[] args) {
// create a string
String name = "Programiz";
System.out.println("Characters in " + name + " are:");
// loop through each element
for(int i = 0; i