本文共 2220 字,大约阅读时间需要 7 分钟。
?Java?????????????????????????????String s1 = new String("hello")?String s2 = "hello"???????????
s1 = new String("hello")?
main()??????new????????new????????????????s1??????String?????String?????s1?????????????????????s2 = "hello"?
String?????s2?s2?????????????????"hello"?????????s1 == s2?
String????????s1?s2?????????????????????????????????????s1 == s2????false?s1.equals(s2)?
String????equals()??????????????????String????????s1.equals(s2)????true?==?????false??Java??????????????????????????????????????????
String s3 = "helloworld";String s1 = "hello";String s2 = "world";String temp = s1 + s2;String finalStr = s3 + "test";
s1 + s2???????????String???s1?s2?????????String?????temp??????????????"test"??????????String?????s3 + "test"???????????String???String??????????s3?"test"?????????finalStr??????????????temp == s1 + s2?
temp?????????s1 + s2????????temp == s1 + s2????true?**finalStr == "helloworld" + "test"`?
"helloworld" + "test"???????????String???String??????????"helloworldtest"???????finalStr?????????"helloworldtest"???????????finalStr == "helloworld" + "test"????true?temp.equals(s1 + s2)?
temp???????s1 + s2?????????temp.equals(s1 + s2)????true?finalStr.equals("hello" + "world")?
"hello" + "world"?????????????finalStr?????????finalStr.equals("hello" + "world")????true?**String s = new String("hello")**???2????
**String s = "hello"**????1????
????????
???new??????????????????????????????????
转载地址:http://ywqe.baihongyu.com/