aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is the different " Watch "what is the different " New topic
Author

what is the different

William Janet
Greenhorn

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: 36

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..


BM
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
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
2 complex problems
Best way to figure out overlapping of strings
2 complex problems
still new to testing, how do I test this method:
Reverse 5 digit number by multiplying 4