Java Hub

For string comparison, == operator or equals method which we should prefer? And why?

1      Reply

as far as I know, you should use equals method for string, which equals() compares the contents of the string, where as == will compare the objects, so == will only be true if they both are point to same objects

Reply
Super friendly <br/>code & developer communities

Super friendly
code & developer communities

A place for coders and developers to share, learn and grow together.