Java :: Check whether two Strings are equal without using the equality(==) operator or the equals() method.
You can exploit the uniqueness property of Set Collection
to accomplish this.
Observe the following code:
|
|
The size of set will be greater than 1 only if the given strings are different. The add
method will internally use equals()
and hashCode()
methods.
Author: Deepu Mohan Puthrote
Link: https://deepumohan.com/tech/java-check-whether-two-strings-are-same-without-equality-operator/
This work by Deepu Mohan Puthrote is licensed under a Creative Commons Attribution 4.0 International License