
Comparing Constant Strings with String Variables
To avoid problems, you should never compare a string variable with a string constant, because string variables may have a null value, in which case your code will throw a NullPointerException.Here’s an example: String strName = null;strName = getName(); //some call which retrives name from DBif(strName.equals(“Ritesh Patel”)) { // some