1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package string;

public class StringDemo {
public static void main(String[] args) {
String str = "hello";
for (int i = 0; i < str.length(); i++) {
/*
h e l l o
i = 0 1 2 3 4
*/
char ch = str.charAt(i);// charAt:提取字符串中某个索引位置处的字符
System.out.println(ch);
/*
* 控制台输出:
* h
* e
* l
* l
* o
*/
}
}
}