StringBuffer与String的区别

直接上代码,原因自己找,自己发现才是进步。

package learnIng;

public class StringBufferTest {
    public static void main(String[] args) {
        String a = "a";
        String c = a;
        String b = "b";
        a = a + b;
        StringBuffer m = new StringBuffer("a");
        StringBuffer n = m;
        m.append("b");
        System.out.println(a.equals(c));
        System.out.println(a == c);
        System.out.println("------------");
        System.out.println(m.equals(n));
        System.out.println(m == n);
    }
}

结果:
false
false


true
true
结果为什么是这样?

相关推荐
©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页