1String scientistName = "Isaac Newton";
2
3for (int i = 0; i < scientistName.length(); i++) {
4 System.out.print(scientistName.charAt(i) + " "); // I s a a c N e w t o n
5}
6
7//*********************************************************
8// you can cast a string into a char[]
9String str = "strings are not primitive types!";
10
11
12for (char ch : str.toCharArray()) {
13 System.out.print(scientistName.charAt(i) + " ");
14 }
15}
16
17
18
19
20
1String s = "...stuff...";
2
3for (int i = 0; i < s.length(); i++){
4 char c = s.charAt(i);
5 //Process char
6}
1String s = "Techie Delight";
2
3// convert string to `char[]` array
4char[] chars = s.toCharArray();
5
6// iterate over `char[]` array using enhanced for-loop
7for (char ch: chars) {
8 System.out.print(ch);
9}
1String s = "...stuff...";
2
3for (int i = 0; i < s.length(); i++){
4 char c = s.charAt(i);
5 //Process char
6}
7