String a = new String(new char[] { 'a', 'b', 'c', 'd' });
2012-10-21 21:28
316 查看
public class StringInternTest2 { public static void main(String[] args) { // 使用char数组来初始化a,避免在a被创建之前字符串池中已经存在了值为"abcd"的对象 String a0="abcd"; String a = new String(new char[] { 'a', 'b', 'c', 'd' }); String b = a.intern(); if (a0 == a) { System.out.println("a0 == a"); } else { System.out.println("a0 != a"); } if (b == a) { System.out.println("b被加入了字符串池中,没有新建对象"); } else { System.out.println("b没被加入字符串池中,新建了对象"); } } } /* a0 != a b没被加入字符串池中,新建了对象 */
相关文章推荐
- window平台下 Eclipse Ndk开发中的Method 'NewStringUTF' could not be resolved问题
- window平台下 Eclipse Ndk开发中的Method 'NewStringUTF' could not be resolved问题
- Android: Type Method 'NewStringUTF' could not be resolved 的完美解决
- Eclipse Ndk开发中的Method 'NewStringUTF' could not be resolved问题
- 解决NDK开发中的 Method 'NewStringUTF' could not be resolved
- 【android】解决NDK开发中的 Method 'NewStringUTF' could not be resolved
- window平台下 Eclipse Ndk开发中的Method 'NewStringUTF' could not be resolved问题
- new year's resolutions
- reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0xbffffffffffff9a3
- 在New comers' training 上听到Microsoft的六个价值观
- VS2008中使用GDI+(error C2660: 'new' : function does not take 3 parameters)
- 即时通讯(环信)-bug Implicit declaration of function 'NSEaseLocalizedString' is invalid in C99
- Incorrect string value: '\xE4\xBC\x9A\xE5\x91\x98' for column 'recipient' at row 1
- 关于String s = new String("xyz"); 创建几个对象的问题
- eXpressApp Framework 8.1.4 released on 30 May 2008 and What'a New
- Incorrect string value: '/xEF/xBC/x88200...' for column 错误提示解决方法
- 014_03_30工作日志:warning C4081: expected 'newline'; found ';'
- Mysql 插入中文错误:Incorrect string value: '\xE7\xA8\x8B\xE5\xBA\x8F...' for column 'course' at row 1
- 面试题--String s=new String("xyz"); 创建了几个对象
- 警告: Can't transform property 'acceptEvent' from java.lang.String into java.util.List. Will register