You can exploit the uniqueness property of Set Collection
to accomplish this.
Observe the following code:
1 2 3 4 5 6 7 8 9 10 |
|
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.