对于String对象,可以使用=赋值,也可以使用new关键字赋值,两种方式有什么区别?

当你看见这个标题的时候,你可能会下意识的去想一下,这两种方式到底有什么样的区别呢?

且看下面的demo,自然便区分开了

* com.b510.test; * Problem: 8 *对于String对象,可以使用”=”赋值,也可以使用”new”关键字赋值,,两种方式有什么区别? 9 *也即:10 *String testStrA = “abc”;11 *String testStrB = new String(“abc”);12 * Jone Hongten14 * @create date:2013-10-31 1.0 StringTest { main(String[] args) {20String testStrA = “abc”;21String testStrB = new String(“abc”);22System.out.println(“testStrA == testStrB ? ” + (testStrA == testStrB ? true : false));2324String testStrC = “abc”;25System.out.println(“testStrA == testStrC ? ” + (testStrA == testStrC ? true : false));2627String testStrD = “ab”;28String testStrE = “c”;29String testStrF = testStrD + testStrE;30System.out.println(“testStrA == testStrF ? ” + (testStrA == tsetStrF ? true : false));31 }32 }却坐在不足一平米的椅子上。

对于String对象,可以使用=赋值,也可以使用new关键字赋值,两种方式有什么区别?

相关文章:

你感兴趣的文章:

标签云: