zoukankan      html  css  js  c++  java
  • String ,StringBuilder ,StringBuffer

    String ,代表字符序列不可变的字符串,且Sring不需要线程安全,线程不安全的版本,因为String本身是不可变的类,
    而不可变类总是线程安全的。
    StringBuilder ,StringBuffer代表字符序列可变的字符串,其中StringBuiler是线程不安全的版本,StringBuffer是线程安全版本。
    public class ImmutableString {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String str = "hello";
            System.out.println(System.identityHashCode(str));
            
            str = str + "java";
            System.out.println(System.identityHashCode(str));
            str = str + ", crazyit.org";
            System.out.println(System.identityHashCode(str));
        }
    
    }
    25860399
    5184781
    33311724




    public class MutableString {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            StringBuilder str = new StringBuilder("Hello");
            System.out.println(str);
            System.out.println(System.identityHashCode(str));
            str.append(" java");
            //str = str + "java";
            System.out.println(str);
            System.out.println(System.identityHashCode(str));
            //str = str + ", crazyit.org";
            str.append(", crazyit.org");
            System.out.println(str);
            System.out.println(System.identityHashCode(str));
        }
    
    }
    Hello
    31843011
    Hello java
    31843011
    Hello java, crazyit.org
    31843011
    

      

  • 相关阅读:
    CNN comprehension
    Gradient Descent
    Various Optimization Algorithms For Training Neural Network
    gerrit workflow
    jenkins job配置脚本化
    Jenkins pipeline jobs隐式传参
    make words counter for image with the help of paddlehub model
    make words counter for image with the help of paddlehub model
    git push and gerrit code review
    image similarity
  • 原文地址:https://www.cnblogs.com/fxyfirst/p/4135637.html
Copyright © 2011-2022 走看看