foreach 是用于简化for对数组的输出的,Java 中的用法是:
for(type x:collection);
举个例子:
public class ForeachDemo {
public static void main(String args[]) {
String str1 = "Hello!";
char c[] = str1.toCharArray();
for(char i:c) {
System.out.print(i+"\t");
}
}
}