Which class would work best for a non-ordered list of pairs? I’ll be taking a bunch of (float,short) pairs and will need to be able to perform simple math (like multiplying the pair together to return a single float, etc). List only takes one argument, and HashMap won’t allow duplicates (as far as I know). Any thoughts?
Share
You can use the
Entry<U,V>class thatHashMapuses but you’ll be stuck with its semantics ofgetKeyandgetValue:My preference would be to create your own simple
Pairclass:Then of course make a
Listusing this new class, e.g.:You can also always make a
Lists ofLists, but it becomes difficult to enforce sizing (that you have only pairs) and you would be required, as with arrays, to have consistent typing.