简体   繁体   中英

Java 1D array list collection .contains or Hash-Map.containsKey speed

Our db have around 400k strings (usernames) at the moment that will need to be checked do they exist on request. Due to large amount of requests needed to check in single second (and because data in mysql will be updated only periodically) it will probably be better to use java instead of mysql query. So my thought is that ill be better to load data from mysql to java and get result if some specific usernames exist in it instead of overheating mysql.

And so my question is, to which one should i load records to, to array ArrayList list collection map HashMap or something third if you can think of, for best speed for only to check if (per request) one username is on that list or not?

You can find details on how each is implemented in the java docs. I believe ArrayList will do a linear search. So HashMap is most likely better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM