This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling equals method on String

 
shashi kir
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a String s="apple"
What is the difference between s.equals("apple") and "apple".equals(s)? and which is better? Please post the correct answer
 
Campbell Ritchie
Sheriff
Pie
Posts: 47261
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends which language you are using. Both are valid syntax in Java, but they mean different things. I think only the one with = is valid SQL syntax, but you should check whether you want "apple" or 'apple' in SQL.

If you try passing s in Java and s is null, then s.equals... will throw a NullPointerException and "apple".equals(s) will evaluate to the value false.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic