Java Class that implements Map and keeps insertion order?

后端 未结 9 2283
一向
一向 2020-11-22 11:28

I\'m looking for a class in java that has key-value association, but without using hashes. Here is what I\'m currently doing:

  1. Add values to a Hashtable<
9条回答
  •  醉话见心
    2020-11-22 11:52

    You can use LinkedHashMap to main insertion order in Map

    The important points about Java LinkedHashMap class are:

    1. It contains onlyunique elements.
    2. A LinkedHashMap contains values based on the key 3.It may have one null key and multiple null values. 4.It is same as HashMap instead maintains insertion order

      public class LinkedHashMap extends HashMap implements Map 
      

    But if you want sort values in map using User-defined object or any primitive data type key then you should use TreeMap For more information, refer this link

提交回复
热议问题