Implement both Map and List interface in Java?

前端 未结 6 1786
死守一世寂寞
死守一世寂寞 2020-12-19 09:51

I\'d like to have an object that implements both the Map and the List interfaces in Java. The idea is similar to the problem in this question: Java Ordered Map

I wan

6条回答
  •  长情又很酷
    2020-12-19 10:28

    In addition to what Dave Costa said you should use LinkedHashMap. This is Map but it preserves order of elements insertion.

    As map it implements values() method, so you can say new ArrayList(map.values()).get(0) to mimic list functionality.

    but you also can say map.get("one") because it is just a map implementation.

提交回复
热议问题