melbel profile image 91

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 image62

Software Development (techa2zsolution) says

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

3 weeks ago
 |  Comment