Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit103dd52

Browse files
author
jsquared21
committed
Edit method MyHashMap.put(key, value)
1 parent2e8e9b6 commit103dd52

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
publicVget(Kkey) {
9191
intindex =hash(key.hashCode());
9292
intj =0;
93-
93+
9494
while (table.get(index) !=null) {
9595
if (table.get(index).getKey().equals(key)) {
9696
returntable.get(index).getValue();
@@ -126,8 +126,8 @@ public V put(K key, V value) {
126126
intj =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
VoldValue =entry.getValue();
133133
// Replace old value with new value

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp