03 | public class StringDemo4 { |
04 | public static void main(String[] args) { |
05 | String s1 = new String( "hello" ); |
06 | String s2 = new String( "hello" ); |
07 | System.out.println(s1==s2); |
08 | System.out.println(s1.equals(s2)); |
10 | String s3 = new String( "hello" ); |
12 | System.out.println(s3==s4); |
13 | System.out.println(s3.equals(s4)); |
17 | System.out.println(s5==s6); |
18 | System.out.println(s5.equals(s6)); |
面试题2:
03 | public class StringDemo5 { |
04 | public static void main(String[] args) { |
07 | String s3 = "helloworld" ; |
08 | System.out.println(s3==s1+s2); |
09 | System.out.println(s3.equals(s1+s2)); |
10 | System.out.println(s3== "hello" + "world" ); |
11 | System.out.println(s3.equals( "hello" + "world" )); |
/*
* 结论:
* 字符串如果是变量相加,先开空间再拼接(一开空间,地址就绝对不一样)
* 字符串如果是常量相加,是先加,然后在常量池找,如果有就直接返回,否则就创建
我们用Java的反编译工具XJad就可以看出来其中的原因
*/
(window).load(function (){
var imgs =("#articleCon img"); for(var i = 0 ; i