Java»ù´¡ÎÊÌ⣺java.lang.String
ÔÎÄ: http://forum.javaeye.com/viewtopic.php?t=17912§Ö÷µÄÎÊÌâÎʵĺ¬º¬ºýºý:flyjie¸ø³öÁ˷dz£ÏêϸµÄ½âÊÍ£¬²»¹ý¾ÍÊÇûÓнâÊÍStringʵÀý»¯µÄÌØÊâ·½ÃæÒÔ¼°Intern()·½·¨µÄº¬Òå-------------------------------------------------------------------------------------------------------------------------------------------------------------------------java´úÂë: String str ; ÕâÑùÉùÃ÷strËüÖ»Ö§ÊÇÒ»¸ö¶ÔÏóµÄreference£¬²»»á²úÉúʵ¼ÊµÄ¶ÔÏó¡£Èç¹ûûÓгõʼ»¯str£¬±àÒëʱ±ã»á·¢Éú´íÎó¡£ java´úÂë: String str1=new String("test"); String str2 = "test"; str1ÊÇÒ»¸öеĶÔÏó¡£new¹Ø¼ü×ÖµÄÒâ˼¾ÍÊÇ´´½¨Ä³¸öеĶÔÏ󡣶østr2ÊÇÒ»¸ö¶ÔÏóµÄÒýÓᣡ¡ËüÃǵÄÄÚÈÝÏàͬ£¬µ«ÄÚ´æµØÖ·ÊDz»Ò»ÑùµÄ¡£ javaÖжÔÏóµÄÒýÓôæÔÚStack(Õ»)ÖУ¬¶ø¶ÔÏóÓÉHeap(¶Ñ)·ÖÅä¿Õ¼ä¡£ 3¡¢ÒýÓÃ==±äÁ¿? ¡¡²»Ò»¶¨ java´úÂë: ¡¡ public class TestString { public static void main(String[] args) { String s1 = "test"; String s2 = new String("test"); if (s1 == s2) System.out.println("s1 == s2"); else System.out.println("s1 != s2"); if (s1.equals(s2)) System.out.println("s1 equals s2"); else System.out.println("s1 not equals s2"); } } ÎÒÃǽ« s2 Óà new ²Ù×÷·û´´½¨³ÌÐòÊä³ö£ºs1 != s2 s1 equals s2. java´úÂë: s2 = s2.intern(); ÔÚÄã¼ÓÉÏÕâ¾ä»°ºó£¬ÉÏÃæµÄ³ÌÐòÊäÈ룺s1 == s2¡¡s1 equals s2 ¶øString a = "test" ; String b = "test" ; a == b »á·µ»Øtrue; ÕâÀïa="test"ʱ´´½¨Ò»¸öÔÚÕ»ÖеÄreference, b=testʱjvm·¢ÏÖÕ»ÖÐÒÑ´æÔÚÃûΪ"test"µÄ×Ö·û´®£¬Ö±½ÓÒýÓ᣽áÂÛ£ºString ÊǸö¶ÔÏó£¬Òª¶Ô±ÈÁ½¸ö²»Í¬µÄString¶ÔÏóµÄÖµÊÇ·ñÏàͬÃ÷ÏÔµÄÒªÓõ½ equals() Õâ¸ö·½·¨. ¶ø== ±È½ÏµÄÊÇÄÚ´æµØÖ·µÄÖµ¡£ 4¡¢private final String a = "test", Õâ¸öaÊôÓÚ³£Á¿£¬´æ·ÅÔÚ³£Á¿´æ´¢¿Õ¼ä(CS)ÖС£ 5¡¢½¨ÒéÄã¿´¿´<<ÉîÈëdz³öjavaÐéÄâ»ú>>Ò»Êé¡£ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------×ܽá1. ÔÚѧϰJAVAµÄʱºò¾ÍÖªµÀ£½£½±È½ÏµÄÊÇÄÚ´æµØÖ·.¶øequals±È½ÏµÄÊÇÄÚ´æµØÖ·¶ÔÓ¦µÄÖµ£¡£¨¿ÉÊÇ»¹ÊÇÓкܶàµÄ
Ïà¹ØÎĵµ£º
XMLÎļþ book.xml
<book>
<person>
<first>Kiran</first>
<last>Pai</last>
<age>22</age>
</person>
<person>
<first>Bill</first>
<last>Gates</last>
<age>46</age>
</person>
<person>
&l ......
ת×Ôwww.bitsCN.com
ÕªÒª£º±¾ÎÄ´ÓJavaÒì³£×î»ù±¾µÄ¸ÅÄî¡¢Óï·¨¿ªÊ¼½²ÊöÁËJavaÒì³£´¦ÀíµÄ»ù±¾ÖªÊ¶£¬·ÖÎöÁËJavaÒì³£Ìåϵ½á¹¹£¬¶Ô±ÈSpringµÄÒì³£´¦Àí¿ò
¼Ü£¬²ûÊöÁËÒì³£´¦ÀíµÄ»ù±¾ÔÔò¡£²¢ÇÒ×÷ÕßÌá³öÁË×Ô¼º´¦ÀíÒ»¸ö´óÐÍÓ¦ÓÃϵͳÒì³£µÄ˼Ï룬²¢Í¨¹ýÉè¼ÆÒ»¸öÒì³£´¦ÀíµÄ¿ò¼ÜÀ´ÂÛÊö´Ë˼Ïë¡£
Ò»¡¢ Òì³£µÄ¸ÅÄîº ......
Ò»£¬JavaÓïÑÔÖеĶÔÏóÒýÓÃ
C++ÖÐÖ¸ÕëºÍÒýÓüæÓУ¬¶øJavaÖÐûÓÐÖ¸ÕëµÄ¸ÅÄÍêÈ«ÓÃÒýÓÃÌæ´ú¡£ÈçC++ÖÐÒ»Ñù£¬ÒýÓÃÊÇÎÒÃǸø±äÁ¿µÄÒ»¸ö“±ðÃû”£¬Ò»¸ö±äÁ¿¿ÉÒÔÓжà¸ö“±ðÃû”¡£ÒýÓõÄÖµÊÇÒ»¸öÄÚ´æµØÖ·£¬ÔÚ¶ÔÏóµÄÒýÓñ»¶¨Òåʱ£¬È磺
String s; //´ËʱsֵΪ¿Õ£¬ÏµÍ³²¢Ã»ÓÐΪsËùÖ¸µÄ¶ÔÏó·ÖÅäÄÚ´æ
s = ......
Ò».¶Ñ:ÓÃnew¹Ø¼ü×Ö½¨Á¢,´æ·Å¶ÔÏóµÄÄÚÈÝ,GC¸ºÔð×Ô¶¯»ØÊÕ
ÄãÓÃÊ®¼¸¸öÂ齫ÅÆÊúÖ±µþ³ÉÒ»ÞûÕâ½Ð¶Ñ£¬Äã¿ÉÒÔ´ÓÉÏÃæ¡¢ÏÂÃæ¡¢ÖмäÈÎÒâ³é³öÒ»ÕÅÅÆ£¬Ò²¿ÉÒÔÈÎÒâ²åÈëÒ»ÕÅ¡£ËùÒԶѺÜÁé»î£¬µ«²»°²È«¡£¶ÔÓÚ¶ÔÏó£¬ÎÒÃÇÒª¶¯Ì¬µØ´´½¨¡¢Ïú»Ù£¬²»ÄÜ˵ºó´´½¨µÄ¶ÔÏóûÓÐÏú»Ù£¬ÏÈÇ°´´½¨µÄ¶ÔÏó¾Í²»ÄÜÏú»Ù£¬ÄÇÑùµÄ»°ÎÒÃǵijÌÐò¾Í´ç²½ÄÑÐУ¬ËùÒÔJavaÖ ......