迭代中插入爲了LinkedHashMultimap
is a documented behavior
實施Multimap
不允許重複的鍵值項,並返回集合,其迭代器按照該數據添加到多重映射排序。
並將開箱的,看到wiki page on Multimap
implementations:
| Implementation | Keys behave like... | Values behave like.. |
|:---------------------|:--------------------|:---------------------|
| LinkedHashMultimap** | LinkedHashMap | LinkedHashSet |
`**` `LinkedHashMultimap` preserves insertion order of entries,
as well as the insertion order of keys, and the set of values associated with any one key.
代碼示例:
LinkedHashMultimap<String, String> m = LinkedHashMultimap.create();
m.put("a", "foo");
m.put("b", "bar");
m.put("a", "baz");
m.get("a").forEach(System.out::println); // outputs "foo" and "baz"
」同樣,get,removeAll和replaceValues也會返回按它們添加順序遍歷值的集合。「混淆在哪裏? –