1. fori循环遍历字符串
public static void main(String[] args) {
String str = "hello world";
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
System.out.print(ch+" ");
}
}
2. foreach遍历字符串数组
public static void main(String[] args) {
String[] str = new String[] {"hello","world"};
for (String x:str) {
System.out.print(x+" ");
}
}