加载中...

StringBuildER、StringBuffer

/**
测试StringBuildER、StringBuffer
*/
public class TestStringBuilder {
    public static void main(String[] args) {
      String str;
      
      //stringbuilder线程不安全,效率高(一般使用它)。stringbuffer线程安全,效率低
      StringBuilder sb = new StringBuilder("abcdefg");
      
      System.out.println(Integer.toHexString(sb.hashCode()));
      System.out.println(sb);
      
      sb.setCharAt(2, 'M');   
      System.out.println(Integer.toHexString(sb.hashCode()));
      System.out.println(sb); //abMdefg
      
  }
}
posted @ 2021-08-14 10:46  nongeason  阅读(32)  评论(0)    收藏  举报