Multiple Keys to Single Value Map Java

后端 未结 4 1025
忘了有多久
忘了有多久 2020-12-03 10:47

I think my question is similar to this one: How to implement a Map with multiple keys? but with an important difference. In that question (if my understanding of it is corre

4条回答
  •  天命终不由人
    2020-12-03 10:58

    Apache Commons Collections has MultiKey.

    import org.apache.commons.collections4.keyvalue.MultiKey;
    
    Map myMap = new HashMap();
    myMap.put(new MultiKey(key1, key2), value);
    
    myMap.get(new MultiKey(key1, key2));
    

    It has the benefit of creating N-dimensional arrays from a Map.

提交回复
热议问题