The moose likes Beginning Java and the fly likes what is the different Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the different " Watch "what is the different " New topic

what is the different

William Janet

Joined: Feb 10, 2011
Posts: 4
What is the difference between these two statements:

1) return foo.equals("abcde");

2) return "abcde".equals(foo);
Buddhika Mawella
Ranch Hand

Joined: Jan 06, 2011
Posts: 39

Think about a situation where variable foo has the value 'null'. when foo is null if you execute
that will create a NullPointerException.
but folowing code will never throw a NullPointerException

since "abcde".equals(null) always return Boolean 'false'.
hope you got it..

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38039
Welcome to the Ranch

Please always tell us what the question is about.
I agree. Here's the link: http://aspose.com/file-tools
subject: what is the different
Similar Threads
still new to testing, how do I test this method:
Reverse 5 digit number by multiplying 4
Best way to figure out overlapping of strings
2 complex problems
2 complex problems