I have a MyMap class that wraps TreeMap. (Say this is a collection of dogs and the keys are strings).
public class MyMap { private TreeMap<String, Dog> map; ... }
I would like MyMap to repeat with a for-each loop. I know how I would do this if my class was a LinkedList wrapper:
public class MyList implements Iterable<Dog> { private LinkedList<Dog> list; ... public Iterator<Dog> iterator() { return list.iterator(); } }
But such a solution does not work for TreeMap, because TreeMap does not have an iterator (). So how can I make MyMap iterable?
And the same question, except for MyMap, wraps HashMap (instead of TreeMap).
Thanks.
source share