Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Dictionary value of type tuple

I want a Dictionary (HashTable, Map, ...) that has one key and several values.

I.e. I want something like

HashTable<Key, [value1, value2]>

How do I get this?

like image 709
ptikobj Avatar asked Feb 22 '26 06:02

ptikobj


1 Answers

The easiest way I think:

Map<Key, List<Value>>

If you would rather just have a tuple (pair, 3, or ...) you can create a Pair class.

class Pair<E,F, ...> {

    public E one;
    public F two;
    ...

}

And then use a Map like so:

Map<Key, Pair<Value, Value>>
like image 163
jjnguy Avatar answered Feb 23 '26 20:02

jjnguy



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!