How can I get a set of values from a value in a ma

2019-09-06 18:11发布

I have a map that contains values which could exist for multiple keys. So I figured I needed to setup a map like this: Map<Integer, Set<Long>> myMap = new HashMap<Integer, Set<Long>>

I would like to retrieve a value from a key's set of values.

The problem is that I don't know how to add a long value to the set in myMap and I don't know how to check if myMap contains a value in it's values' set.

Is this implementation incorrect?

标签: java map set
1条回答
Juvenile、少年°
2楼-- · 2019-09-06 18:34

You need something like this.

if(myMap.containsKey(myKey)){
    myMap.get(myKey).add(value);
}
查看更多
登录 后发表回答