Saturday, 2 July 2016

Comparing java Strings with ==










Is it possible to compare Java Strings using == operator?



Why do I often see, that equals() method is used instead?



Is it because when comparing with literal Strings (like "Hello") using == doesn't imply calling equals()?


Answer



there is no custom operator overloading in java. [so you cannot overload it to call equals()]



the equals() ensures you check if 2 Objects are identical,while == checks if this is the exact same object. [so no, using == does not invoke equals()].


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...