Linked Questions
10 questions linked to/from Can Java's hashCode produce same value for different strings?
1 vote
0 answers
317 views
An example of a hashCode() comparison returning true while a equals() method returns false? [duplicate]
I understand it's possible, I just don't understand how. From what I can tell, if a class overrides the hashCode() and equals() methods to consider specified data members, references that instantiate ...
253 votes
11 answers
240k views
Do Java arrays have a maximum size?
Is there a limit to the number of elements a Java array can contain? If so, what is it?
154 votes
10 answers
83k views
Why doesn't String switch statement support a null case?
I am just wondering why the Java 7 switch statement does not support a null case and instead throws NullPointerException? See the commented line below (example taken from the Java Tutorials article on ...
7 votes
5 answers
4k views
How to use String.hashCode to generate primary keys
I understand that this seems to be already discussed and the answer is yes, String.hashCode can generate equal vales for different strings, but quite unlikely (Can Java's hashCode produce same ...
11 votes
4 answers
2k views
How do I prove that Object.hashCode() can produce same hash code for two different objects in Java?
Had a discussion with an interviewer regarding internal implementation of Java Hashmaps and how it would behave if we override equals() but not the HashCode() method for an Employee<Emp_ID, ...
5 votes
2 answers
2k views
Can hashcodes of short string be same?
I have short Strings (less than 10 characters). I will convert it into int and use it as primary key. (I can't use String primary key because of small problems.) I know the hashcodes of Strings of ...
1 vote
2 answers
3k views
Kotlin Convert long String letters to a numerical id
I'm trying to find a way to convert a long string ID like "T2hR8VAR4tNULoglmIbpAbyvdRi1y02rBX" to a numerical id. I thought about getting the ASCII value of each number and then adding them up but I ...
2 votes
2 answers
356 views
What is the key in the Set's underlying HashMap: hash code or the object itself?
Is this sentence from an OCP book correct? A HashSet stores its elements in a hash table, which means the keys are a hash and the values are an Object. I have created below code snippet: class A { ...
0 votes
2 answers
386 views
Java hashcode logic
There are 10 fields in my database. In those 4 fields, 1 field is hash_attr. hash_attr is basically signifies whether incoming row is same or not with the row stored in database. If it is same we don'...
0 votes
1 answer
75 views
Solutions that involve looping over two input arrays: O(n + m) or O(n * m)
I was asked a question in which we're looking for duplicate social security numbers, as in ssn that are in both array A and also array B. My immediate thought was to iterate over each array storing ...