Inserts the key-value pair of KEY and VALUE into this map, replacing the previous value associated to KEY, if any.
(K key, V val)
| 41 | * replacing the previous value associated to KEY, if any. |
| 42 | */ |
| 43 | public void put(K key, V val) { |
| 44 | if (list != null) { |
| 45 | Node lookup = list.get(key); |
| 46 | if (lookup == null) { |
| 47 | list = new Node(key, val, list); |
| 48 | size = size + 1; |
| 49 | } else { |
| 50 | lookup.val = val; |
| 51 | } |
| 52 | } else { |
| 53 | list = new Node(key, val, list); |
| 54 | size = size + 1; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns true if and only if this dictionary contains KEY as the |