Why does the foreach statement not change the element value?

前端 未结 6 1036

How come the following prints boss and not bass?

String boss = \"boss\";
char[] array = boss.toCharArray();

for(char c : array)
{
 if (c== \'o\')
     c =          


        
6条回答
  •  一生所求
    2020-11-22 01:21

    c's value is a copy of the value in array. Access array directly to change the value in question.

提交回复
热议问题