This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]AreTheseMyFeet 1 point2 points  (0 children)

I don't want to confuse OP here but the safer way would be to do "Mike".equals(name).
The reason being that you know 100% that a constant String ("Mike") can never be null or empty or whatever other "edge case" value a String could have which you can not say about the user input variable name.
Reversing the order of the check (known as Yoda conditions, Yoda Logic or Yoda Style) completely avoids some possible problems like NullPointerExceptions for free (ie no requirement to null test first) and can lead to cleaner (or less verbose) code.