I wrote some code that works but I'm not sure. Consider
LinkedList<Iterator<Integer>> iterators;
HashMap<Character, TreeSet<Integer>> map;
for (char c : map.keySet()) {
iterators.add(map.get(c).iterator());
map.remove(c);
}
Even though the original TreeSet has been removed, the iterator seems to work fine (i.e. goes in the original ordering of the TreeSet). I don't quite understand why it's functional--it seems as though there's passing-by-value here instead of passing-by-reference. However, obviously, if I were to write
map.get(c).add(6);
the TreeSet would actually add 6 in the map (not just add 6 to a copy of the TreeSets in the map), indicating get is passing by reference. Can someone help clear up the confusion here?