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