Click here to Skip to main content
15,940,218 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.

What I have tried:

Is == bad? When should it and should it not be used? What's the difference?
Updated 23-Feb-21 2:49am
CoderzF1 13-Feb-21 9:40am    
A lot of source code that I have looked at recently uses the .equals for string comparison, So apparently this is the widely accepted approach.

Share this answer
The == operator compares references not values
The String equals() method compares the original content of the string
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900