Method B will end with a NullPointerException on line zero1, while Method A will never throw it. Some authorities claim this "defensive" programming. They influenced me to do this, although it still doesn't come naturally!
You can also write
if (string1 != null && string1.equals("MyString")) ...
although tools like FindBugs put this as a possible mistake, assuming you have to make sure that line1 is no longer zero. (Can you rely on the evaluation order?).
So there are different schools of thought.
source share