Reputation: 33
I am trying to convert a Python script I wrote to Java. In the script I am using python's native hash() function on strings. I need to find the exact equivalent of this in Java to avoid discrepancies. Thanks in advance!
Upvotes: 2
Views: 1562
Reputation: 4723
The Python method hash(object)
calls
__hash__()
method of an object which are set by default for any object.
The exact equivalent in Java to that is Objects.hashCode(Object)
that calls hashCode()
on the given object and returns the result.
The equivalence is given by the syntax. It may not be given by the underlying hashing algorithm.
Upvotes: 1