To create a LinkedHashMap with accessOrder, the constructor of the LinkedHashMap class can be used with the parameter accessOrder set to true. The syntax is as follows:
val linkedHashMap = LinkedHashMap<Key, Value>(initialCapacity, loadFactor, true)
Where:
- Key
is the type of the keys in the map
- Value
is the type of the values in the map
- initialCapacity
is the initial capacity of the map (optional, defaults to 16)
- loadFactor
is the load factor of the map (optional, defaults to 0.75)
- true
indicates that the access order should be maintained
For example, to create a LinkedHashMap with accessOrder for strings:
val linkedHashMap = LinkedHashMap<String, Int>(16, 0.75, true)
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-09-01 11:00:00 +0000
Seen: 17 times
Last updated: Nov 27 '22