-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashmapLL.java
More file actions
63 lines (55 loc) · 1.39 KB
/
HashmapLL.java
File metadata and controls
63 lines (55 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package lec27;
import java.util.LinkedList;
// using linked list
public class HashmapLL {
LinkedList<Entity> entities = new LinkedList<>();
public void put(String key, String value){
for (Entity entity: entities){
if(entity.key.equals(key)){
entity.value=value;
return;
}
}
entities.add(new Entity(key, value));
}
//****************************
public String get(String key){
for (Entity entity: entities){
if(entity.key.equals(key)){
return entity.value;
}
}
return null;
}
public String remove(String key){
Entity target = null;
for(Entity entity:entities){
if(entity.key.equals(key)){
target = entity;
break;
}
}
String temp = target.value;
entities.remove(target);
return temp;
}
@Override
public String toString(){
String s = "";
s+= "{";
for(Entity entity:entities){
s += (entity.key+" = "+ entity.value +" , ");
}
s +="}";
return s;
}
//**********************************
class Entity{
String key;
String value;
public Entity(String key, String value){
this.key=key;
this.value=value;
}
}
}