Skip to content

Commit 3a48e3f

Browse files
author
jsquared21
committed
Edit method MyHashMap.get(key) for efficiency
1 parent 6fde7c4 commit 3a48e3f

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_01/MyHashMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public V get(K key) {
9090
int index = hash(key.hashCode());
9191

9292
while(table.get(index) != null) {
93-
if (table.get(index).getKey() == key) {
93+
if (table.get(index).getKey().equals(key)) {
9494
return table.get(index).getValue();
9595
}
9696
index++;
@@ -120,7 +120,7 @@ public java.util.Set<K> keySet() {
120120
@Override /** Add an entry (key, value) into the map */
121121
public V put(K key, V value) {
122122
int index = hash(key.hashCode());
123-
123+
124124
while (table.get(index) != null) {
125125
// The key is already in the map
126126
if (table.get(index).getKey().equals(key)) {

0 commit comments

Comments
 (0)