Skip to content

Commit 003eec0

Browse files
author
jsquared21
committed
Edit method MyHashMap.remove(key) for efficiency
1 parent a2e5a72 commit 003eec0

File tree

2 files changed

+2
-2
lines changed

2 files changed

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

Exercise_27/Exercise_27_02/MyHashMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ public V put(K key, V value) {
160160
public void remove(K key) {
161161
int index = hash(key.hashCode());
162162
int j = 0;
163-
163+
164164
while (table.get(index) != null) {
165-
if (table.get(index).getKey() == key) {
165+
if (table.get(index).getKey().equals(key)) {
166166
table.remove(index);
167167
size--; // Decrease size
168168
break; // Remove just one entry that matches key

0 commit comments

Comments
 (0)