[Logo]
Forums Register Login
Calling equals method on String
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
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.
grapes are vegan food pellets. Eat this tiny ad:
ScroogeXHTML 7.1 - RTF to HTML5 / XHTML converter
https://coderanch.com/t/690611/ScroogeXHTML-RTF-HTML-XHTML-converter


This thread has been viewed 715 times.

All times above are in ranch (not your local) time.
The current ranch time is
Feb 18, 2018 02:01:55.