-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHashSet.java
More file actions
40 lines (32 loc) · 815 Bytes
/
HashSet.java
File metadata and controls
40 lines (32 loc) · 815 Bytes
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
package Implementations;
import java.util.Iterator;
public class HashSet<V> implements Iterable<V>{
private HashMap<V, V> map = new HashMap<>();
public void add(V value){
map.set(value, value);
}
public void clear(){
map = new HashMap<>();
}
public void remove(V value){
map.remove(value);
}
public int size(){
return map.size();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("[");
for (Iterator<V> it = map.keys(); it.hasNext(); ) {
sb.append(it.next());
if(it.hasNext())
sb.append(", ");
}
sb.append("]");
return sb.toString();
}
@Override
public Iterator<V> iterator() {
return map.keys();
}
}