What's the exact equivalent of python's native hash() function in Java?

Viewed 926

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!

1 Answers

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.

Related