In Java, which is the most recommended class for dictionary data structure?

I need a data structure to store users that should be retrieved by id. I noticed that there are several classes that implement the map interface. What should be my default choice? All of them seem to me completely equivalent.

+3
source share
6 answers

This probably depends on how many users you plan to have, and if you need to order them or just get individual items by id.

HashMap - , put get, .

TreeMap , log (n) , .

HashMap, ( ). , , , ConcurrentHashMap.

- LinkedHashMap, , HashMap ( hashcode equals), , ( ). ( , ), , ) TreeMap.

+9
+3

, . Sun , , .

.

+2

, , - ?

, , .

+1

( , , , )

Have you considered using a database to store this information? Even if it is SQLite , it will probably be easier than storing your user database in program code or loading the entire data set into memory each time.

0
source

Source: https://habr.com/ru/post/1727241/


All Articles