We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 80fc346 commit 6fde7c4Copy full SHA for 6fde7c4
Exercise_27/Exercise_27_01/MyHashMap.class
3 Bytes
Exercise_27/Exercise_27_01/MyHashMap.java
@@ -120,10 +120,10 @@ public java.util.Set<K> keySet() {
120
@Override /** Add an entry (key, value) into the map */
121
public V put(K key, V value) {
122
int index = hash(key.hashCode());
123
-
+
124
while (table.get(index) != null) {
125
- // Add a new entry (key, value)
126
- if (table.get(index).getKey() == key) {
+ // The key is already in the map
+ if (table.get(index).getKey().equals(key)) {
127
Entry<K, V> entry = table.get(index);
128
V oldvalue = entry.getValue();
129
// Replace old value with new value
0 commit comments