+ 1
Hi all, equal method is used for what?
please explain it thank you
1 Resposta
+ 1
The equals() method is used to test equality between two values of the same type. For example you have two strings which both have the value "hi" but are still different Strings in terms of memory location. If you do this:
System.out.print(str1.equals(str2));
It will print true.
If you try to use ==, it will always return false if they are different Strings because double equals tests for equality in memory location.
There is also an equalsIgnoreCase() method that ignores uppercase and lowercase letters.
Hope that helps, good luck!