java中两种不同的 string赋值比较
2017-05-26 21:04
555 查看
内存分析:
第一个验证程序:
第二个验证程序:
第三个验证程序:
String c =”hello” + “world”; 这条语句
经过编译器优化后,就等于String c =”helloworld”;
第一个验证程序:
public class TestString { public static void main(String[] args) { String a ="hello"; String b ="hello"; String c = new String("hello"); String d = new String("hello"); System.out.print(a==b); // ture System.out.print(a.equals(b)); // ture System.out.print(a==c); //false System.out.print(a.equals(c)); // ture System.out.print(c==d); //false System.out.print(c.equals(d)); // ture } }
第二个验证程序:
public class TestString { public static void main(String[] args) { String a = new String("hello"); String b ="hello"; System.out.print(a==b); // false System.out.print(a.equals(b)); // ture } }
第三个验证程序:
public class TestString { public static void main(String[] args) { String a ="hello"; String b ="world"; String c ="hello" + "world 4000 "; String d ="helloworld"; String e = a + b; System.out.print(c==d); //ture System.out.print(c==e); //false } }
String c =”hello” + “world”; 这条语句
经过编译器优化后,就等于String c =”helloworld”;
相关文章推荐
- java String 两种不同的赋值 比较
- Java String比较两种不同的赋值
- java String 两种不同的赋值 比较
- java String 两种不同的赋值 比较
- Java中两种String对象创建和初始化方式比较
- Java和C#中String直接赋值与使用new创建(==与equals进行比较)的区别
- Java中String两种不同创建方式的区别及intern的用法
- Java中两种String对象创建和初始化方式比较
- java学习日记_23:面向对象之对两种类的赋值方式的比较
- 浅谈java中String的两种赋值方式的区别
- Java中String两种不同创建方式的区别及intern的用法
- Java 创建线程池两种不同方法的比较
- java中Map的两种不同遍历、迭代方式及比较
- Java中两种String对象创建和初始化方式比较
- Java—String的两种赋值方式及区别
- java String 两种不同的赋值 比较
- Java中String两种不同创建方式的区别
- Java基础(11):字符串—深入理解String对象和比较符==和equals的不同
- 004_java中String的两种赋值方式的区别
- Java和C#中String直接赋值与使用new创建(==与equals进行比较)的区别