本站首页    管理页面    写新日志    退出


«July 2025»
12345
6789101112
13141516171819
20212223242526
2728293031


公告

关注电子政务、大型企业应用开发、Web、Workflow、MOM、MDA、RCP、GEF

email:gmluyang@gmail.com


链接

好友
bluedavy-林昊
刑红瑞
SixSun-翻译
Birt中文指南
SixSun-OpenDoc
Eclipse RCP and Web in action(编写中)

我的分类(专题)

日志更新

最新评论

留言板


Blog信息
blog名称:SixSun的Blog
日志总数:152
评论数量:372
留言数量:13
访问次数:2372842
建立时间:2004年12月13日




[J2SE / 基础类]String( Equal , ==, intern())
随笔,  心得体会,  软件技术

SixSun 发表于 2006/3/1 9:48:11

String java.lang.String.intern()Returns a canonical representation for the string object. A pool of strings, initially empty, is maintained privately by the class String. When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned. It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true. All literal strings and string-valued constant expressions are interned. String literals are defined in §3.10.5 of the Java Language Specification Returns:a string that has the same contents as this string, but is guaranteed to be from a pool of unique strings. Test Game:500)this.width=500'> package org.sixsun.designpattern.flyweight; import junit.framework.TestCase; public class TestFlyweight extends TestCase {  String str1;          String str2;          String str3;         String str4;  public static void main(String[] args) { }  public TestFlyweight(String name) {  super(name); }  protected void setUp() throws Exception {  super.setUp();  str1 = "fly";           str2 = "weight";           str3 = "flyweight";               str4 = str1 + str2;  }  protected void tearDown() throws Exception {  super.tearDown(); }  public void testEqual1() {  assertFalse(str3==str4); }  public void testEqual2() {  assertTrue(str3.equals(str4)); }   public void testEqual3() {  assertFalse( str3 == "weight" + "flyweight" ); }  public void testEqual4() {  assertFalse( str3 == (new String("weight") + new String ("flyweight")) ); }   public void testEqual5() {  assertFalse( str3 == new String ("weight" + "flyweight") ); }  public void testEqual6() {  assertFalse( str3.equals("weight" + "flyweight") ); }   public void testEqual7() {  assertFalse( str3 == "weightfly" ); }   public void testEqual8() {  assertFalse( str3 == new String("weightfly") ); }     public void testEqual9() {  assertTrue( str1=="fly" ); }  public void testEqual10() {  assertFalse( str1==new String("fly") ); }  public void testEqual11() {  assertTrue( str1.equals("fly") ); }   public void testEqual12() {  assertFalse(str3==(str1 + str2)); }  public void testEqual13() {  assertFalse(str4==(str1 + str2)); }  public void testEqual14() {  assertFalse((str1 + str2)==(str1 + str2)); }  public void testEqual15() {  assertTrue((str1 + str2).equals(str1 + str2)); }   public void testEqualIntern() {  assertTrue(str3==(str1 + str2).intern()); }  }


阅读全文(3706) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144776081 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号