如何从地图中的值获取一组值? [英] How can I get a set of values from a value in a map?

查看:99
本文介绍了如何从地图中的值获取一组值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个键可能存在的值的地图。所以我想我需要设置一个这样的地图: Map< Integer,Set&Long。>> myMap = new HashMap< Integer,Set&Long。>



我想从一组键值中检索一个值。



问题是我不知道如何在<$ c中添加 long $ c> myMap ,我不知道如何检查 myMap 是否包含其值集合中的值。



这个实现是不正确的吗?

解决方案

你需要这样的东西。 b
$ b

  if(myMap.containsKey(myKey)){
myMap.get(myKey).add(value);
}


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?

解决方案

You need something like this.

if(myMap.containsKey(myKey)){
    myMap.get(myKey).add(value);
}

这篇关于如何从地图中的值获取一组值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆