【发布时间】:2013-03-28 11:44:27
【问题描述】:
为什么下面的打印是boss而不是bass?
String boss = "boss";
char[] array = boss.toCharArray();
for(char c : array)
{
if (c== 'o')
c = 'a';
}
System.out.println(new String(array)); //How come this does NOT print out bass?It prints boss.
【问题讨论】:
-
@KacyRaye 顺便说一句,这是在对象引用类上使用增强的
for循环时的类似行为(这里提出的解决方案是相同的)。