0
点赞
收藏
分享

微信扫一扫

字符串不可变

boom莎卡拉卡 2022-01-15 阅读 36
java

字符串不可变的条件

在String源码中有如下代码:

  /** The value is used for character storage. */
  private final char value[];
 
  /** Cache the hash code for the string */
  private int hash; // Default to 0

这就导致了每次生成的字符串不可变动。每次变动都是生成新的数组;再来一次深拷贝;

举报

相关推荐

什么是字符串不可变性?

可变字符串类和日期相关类

0 条评论