File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the different

 
William Janet
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between these two statements:

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

2) return "abcde".equals(foo);
 
Buddhika Mawella
Ranch Hand
Posts: 40
Eclipse IDE Java Spring
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always tell us what the question is about.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic