Skip to content
Advertisement

How do I use the character’s equals() method in Java?

As the String is an object, you need to use the string.equals(string) method to confirm that the two strings are equal.

However, why do you use the == to check if two chars are equal, char1 == char2, rather than char1.equals(char2)?

Advertisement

Answer

Perhaps, this will help to understand the difference on == vs equals.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement