我相信其他语言,你可以做到以下几点:
for (String foo : new String[]{"string1", "string2", "string3"}) {
//do something with foo
}
然而,对于Java,我收到错误
new String[]{"string1", "string2", "string3"}
在Java中是否可以这样,或者我必须像这样创建新数组:
final String[] bar = {"string1", "string2", "string3"};
for (String foo : bar) {
//do something with foo
}