char[] c = str.toCharArray();
for (int i = 0; i < c.length; i++) {
System.out.println(c[i]);
}
public static void main(String[] args){
String str ="1234567";
int i = 0;
while(iSystem.out.print(str.charAt(i++)+ ",");
}
substr();
用个循环
public static void main(String[] args)
{
String str ="1234567";
char[] array = str.toCharArray();//将字符串转换为字符数组
int size = array.length;
for(int i = 0; i < size; i++)
{
if(i == (size -1)) //如果到了最后一位,不增加","
{
System.out.print(array[i]);
break; //已经到最后一个字符,退出循环
}
System.out.print(array[i] + ",");
}
}