使用(element:collection)使用for循环访问集合时,我对数据所做的更改在循环期间只保留相同。For循环(元素:集合)未进行永久更改
这里是我的代码:
String[] names = {"bob", "fred", "marcus", "robert", "jack", "steve", "nathan", "tom", "freddy", "sam"};
for(String indexData : names)
{
indexData = indexData.toUpperCase();
System.out.println(indexData);
}
System.out.println("this is word 5 in the array: " + names[4]);
输出:
BOB
FRED
MARCUS
ROBERT
JACK
STEVE
NATHAN
TOM
FREDDY
SAM
this is word 5 in the array: jack
我的问题是使用这种类型的循环我怎么做永久性的变化?
需要正常的循环没有提高循环 – 2014-10-26 16:32:14