/**
 * 字符串的特点:一旦被赋值,就不能改变。
 */
public class StringNotChange {
    public static void main(String[] args) {
        String s = "hello";
        s += "world";
        System.out.println("s:" + s); // helloworld
    }

}

输出结果: s:helloworldString 一旦被赋值,就不能改变 原理

前面引用可以变 在常量池里面创建的值 不可以变 (s可变 常量池里面的"hello"不可以变)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-05
  • 2021-10-01
  • 2021-06-23
  • 2022-12-23
  • 2021-05-19
  • 2021-08-29
猜你喜欢
  • 2021-07-31
  • 2021-04-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
相关资源
相似解决方案