它们之间没有任何区别。许多程序员使用第二种方法只是为了确保他们没有得到
NullPointerException。就这样。
String str = null; if(str.equals("test")) { // NullPointerException System.out.println("After"); } if("test".equals(str)) { // No Exception will be thrown. Will return false System.out.println("Before"); }


