Using two (or more) objects as a HashMap key

前端 未结 8 1193
借酒劲吻你
借酒劲吻你 2020-12-13 21:51

I want to store certain objects in a HashMap. The problem is, usually you just use a single object as a key. (You can, for example, use a String.) What I want to do it to us

相关标签:
8条回答
  • 2020-12-13 22:34

    Apache Commons Collections has a multikey map which might do the trick for you:

    https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/keyvalue/MultiKey.html

    It looks like it will handle up to 5 "keys".

    0 讨论(0)
  • 2020-12-13 22:39

    I tend to use a list

    map.put(Arrays.asList(keyClass, keyString), value)
    
    0 讨论(0)
提交回复
热议问题