我想插入重复的键和值,并希望按插入顺序排列它们,在 Java 集合中对此的最佳解决方案是什么?
最佳答案
任何List
将保留插入顺序,并且它们都允许重复的元素。
An ordered collection (also known as a sequence). The user of this interface has precise control over where in the list each element is inserted.
在标准 Java 中没有具有这些属性的 key-value
结构,但是 Guava 的 LinkedListMultiMap
可能有您要找的东西。
An implementation of ListMultimap that supports deterministic iteration order for both keys and values. The iteration order is preserved across non-distinct key values.
关于java - 在 Java 中插入重复键值对并获取它们的插入顺序的最佳方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21368559/