Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a single key and multi value data structure in Java?

I would like to store multiple values for a single key and must be able to retrieve the specific value.

Is there any data structure in Java which have this kind of functionality? If so, please let me know.

like image 638
serenity Avatar asked Jul 08 '26 00:07

serenity


2 Answers

You may use Map<key,List<T>>

HashMap<String,ArrayList<String>> map;
like image 71
KV Prajapati Avatar answered Jul 10 '26 13:07

KV Prajapati


There is no support in JDK. What you want is a Multimap and guava library provides it.

like image 42
Aravind Yarram Avatar answered Jul 10 '26 14:07

Aravind Yarram



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!