String 中的==

来源:互联网 发布:php foreach 编辑:程序博客网 时间:2024/06/04 20:11

直接String出来的常量是储存在栈。
new 出来的对象是保存在堆里面。

 String a = "hello"; String b = "hello"; String c = new String("hello"); System.out.println(b==a);//true System.out.println(c==a);//false

常量相加是直接相加,变量相加会使用StringBuffer实现。

String a="hello";String b="world;String c=“helloworld";String d="hello"+"world";System.out.println(c==(b+c));//falseSystem.out.println(c==d);    //true
阅读全文
0 0
原创粉丝点击