public class ST<Key, Value> { public void put(Key k, Value v) {...} public Value get(Key k) {...} public void delete(Key k) {...} public Iterable<Key> keys(); public boolean contains(Key key) {...} public int size() {...} public boolean isEmpty() {...} }
- put(k,v);
Inserts the pair (k,v) if k not in the table. Otherwise replaces k's value with v.
- v = get(k);
Returns the value associated with k if the pair (k,v) is in the table. Otherwise get returns null.
- delete(k)
If (k,v) is in the table, that pair is removed. Otherwise, no change.
- p = keys();
Returns a reference to some object that implements Iterable<Key> (The only method in Iterable<Key> is Iterator<Key> iterator().)
So p.iterator() can be used to retrieve each of the keys in the symbol table, one at a time.
Question: How can you print all the key value pairs?