I have a String that contains hash (it was automatically generated by third party program) and I have another String that do not contain hash and I need to compare to the first String.
Method .equals() give false.
How else I can compare them?
If I understood it correctly, there are two String to compare, one is the original String (s1) and the second String which contains the original String + its hash (s2) inserted by a 3rd party program. If so, the built-in equals() method will not return true. I would be creating my own implementation of equals() method to check this.
These two methods should do the trick, but I prefer the second one.
private static boolean equals(String s1, String s2) {
String s1Hash = String.valueOf(s1.hashCode());
return (s2.contains(s1) && s2.contains(s1Hash));
}
private static boolean equals2(String s1, String s2) {
String s1Hash = String.valueOf(s1.hashCode());
String s2NoHash = s2.replace(s1Hash,"");
return (s1.equals(s2NoHash));
}
Hope this answers what you are looking for. Otherwise, a concrete example to describe the problem will be good.
==for strings (btw==is not a "method").