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


BM
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38859
    
  23
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