A
A
Alexander2014-04-01 10:34:59
Java
Alexander, 2014-04-01 10:34:59

How is HashCode generated for string variables in Java?

Can we hope for the uniqueness of the number if the string is different?

String A = "AA";
String B = "BB";
String a = "aA";
// Всегда должно быть - "A.Equals(a) = false";

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
svd71, 2014-04-01
@svd71

1. If you install raw Java, you can see the sources.
2. At the expense of uniqueness, I don’t remember exactly, but everything seems to be as you need. But it is better to look in the raw.
3. The uniqueness of the hash can be taken as the address of the object (for example, the this variable with casting for the type).

V
vans239, 2014-04-01
@vans239

But it's enough to go into the String class and see. Even in the javadoc it is displayed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question