serenity
serenity

Reputation: 159

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.

Upvotes: 2

Views: 4726

Answers (3)

stryba
stryba

Reputation: 2027

What is wrong with Map<Key, List<Element>>?

Upvotes: 1

KV Prajapati
KV Prajapati

Reputation: 94645

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

HashMap<String,ArrayList<String>> map;

Upvotes: 9

Aravind Yarram
Aravind Yarram

Reputation: 80176

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

Upvotes: 8

Related Questions