Have one object
of type A
that is related to a bunch of objects
of type B
and want to store all objects
of type A
and easily access their type B
relations.
What's the best (built-in?) data structure doing this in Java?
You could have a Map of type A
objects to a List or Set (or whichever Collection works best) of type B
objects, like:
Map<A,List<B>> map = new HashMap<A,List<B>>();
Or use Google's MultiMap interface, which will do essentially the same as above, but with less work on your part.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With