Is there an IdentityHashMap implementation that maintains insert order?
问题 I need a HashMap that (1) matches keys by Object reference, and (2) maintains insertion order when iterating These functionalities are implemented in IdentityHashMap and LinkedHashMap separately. Is there any way to get a data structure that suits my need? Either one that is present in Java standard OR 3rd party libraries (like Guava), OR by using some trick on LinkedHashMap maybe, so that it uses object reference for matching keys? 回答1: You can use Guava's Equivalence for this: Equivalence