Skip to content

Commit 103dd52

Browse files
author
jsquared21
committed
Edit method MyHashMap.put(key, value)
1 parent 2e8e9b6 commit 103dd52

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed
3 Bytes
Binary file not shown.

Exercise_27/Exercise_27_02/MyHashMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public java.util.Set<MyMap.Entry<K, V>> entrySet() {
9090
public V get(K key) {
9191
int index = hash(key.hashCode());
9292
int j = 0;
93-
93+
9494
while (table.get(index) != null) {
9595
if (table.get(index).getKey().equals(key)) {
9696
return table.get(index).getValue();
@@ -126,8 +126,8 @@ public V put(K key, V value) {
126126
int j = 0;
127127

128128
while (table.get(index) != null) {
129-
// Add a new entry (key, value)
130-
if (table.get(index).getKey() == key) {
129+
// The key is already in the map
130+
if (table.get(index).getKey().equals(key)) {
131131
Entry<K, V> entry = table.get(index);
132132
V oldValue = entry.getValue();
133133
// Replace old value with new value

0 commit comments

Comments
 (0)