Example 1: Loop through each character of a string using for loop
Output
Characters in nodmek are: P, r, o, g, r, a, m, i, z,
In the above example, we have used the for-loop to access each element of the string. Here, we have used the charAt() method to access each character of the string.
Example 2: Loop through each character of a string using for-each loop
Output
Characters in string "nodmek": P, r, o, g, r, a, m, i, z,
In the above example, we have converted the string into a char array using the toCharArray(). We then access each element of the char array using the for-each loop.