① String str = "";
str + null = "null"//字符串null, 不是关键字
② public class test {private String str = "";public void test1(){if(str + "" == ""){System.out.println("不执行!");}if("" + "" == ""){System.out.println("执行1!");}if((str+ "").equals("")){System.out.println("执行2!");}}public static void main(String[] args) {test test = new test();test.test1();}}
结果:
执行1!执行2!
==: 比较的是内存地址
equals: 比较的是值