Search code examples
javaguavabimap

Is there a BiMap implementation with predictable iteration ordering (insertion order)?


The standard library LinkedHashSet is a HashSet that provides insertion-order iteration. Is there a version of Guava's BiMap that maintains insertion-order iteration on keys and values? I do need the BiMap to be mutable, so ImmutableBiMap is not sufficient for my purpose.


Solution

  • The only available implementation is ImmutableBiMap<K,V>. You can check the implementations here. You can use a LinkedHashMap and convert it to with copyOf(Map<? extends K,? extends V> map) to make it an ImmutableBiMap<K,V>. Will it work for you?