Welcome to the World of Online Learning:
Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a Java Program to Iterate through each characters of the string.
PROGRAM: Java Program to Iterate through each characters of the string.
/*Java Program to Iterate through each characters of the string.*/
1: Loop through each character of a string using for loop
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<name.length(); i++) {
// access each character
char a = name.charAt(i);
System.out.print(a + “, “);
}
}
}
2: Loop through each character of a string using for-each loop
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 + “, “);
}
}
}