String can't change. But int, char can change

后端 未结 7 1516
暖寄归人
暖寄归人 2020-12-03 21:24

I\'ve read that in Java an object of type String can\'t change. But int and char variables can. Why is it? Can you give me an example?

Thank you. (I am a newer -_- )

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 22:07

    int and char can't change either. As with strings, you can put a different value into the same variable, but an integer itself doesn't change. 3 will always be 3; you can't modify it to be 4.

提交回复
热议问题