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