melbel profile image 99

How do I compare strings in Java?


I've always used == to compare strings until now. I ran into an error, so I decided to change one of the equals signs to .equals() and this solved my problem. Why didn't == work? Are there cases where == should not be used and .equals() should be used instead (obviously aside from fixing the bug.) I'm not sure I really see a difference between the two operators. What's the difference?

 

sort by best latest

techa2zsolution profile image60

Software Development (techa2zsolution) says

You can help the HubPages community highlight top quality content by ranking this answer up or down.

8 months ago
 |  Comment
Shubhankar Sharma profile image46

Shubhankar Sharma says

You can help the HubPages community highlight top quality content by ranking this answer up or down.

6 months ago
 |  Comment