Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 获取所有Hashmap索引大小的总和_Android_Hashmap - Fatal编程技术网

Android 获取所有Hashmap索引大小的总和

Android 获取所有Hashmap索引大小的总和,android,hashmap,Android,Hashmap,我正在实现一个逻辑,其中我必须将某个整数乘以其中hashmap值的大小。不幸的是,我无法做到这一点。附件中的图片可以为我提供所有索引的大小。现在我想求所有大小的和,即0+2+1+1,然后与另一个整数相乘。可能吗?请帮助我,因为我没有哈希映射的经验 编辑:写在顶部的尺寸(即4)不是我需要的尺寸。这个大小基本上是有多少个索引的大小,有4个。但是,我需要以下大小的总和,即如果索引2中有4个值,那么总数将为6 int numberToMultiply = 0; int total = 0; for (S

我正在实现一个逻辑,其中我必须将某个整数乘以其中hashmap值的大小。不幸的是,我无法做到这一点。附件中的图片可以为我提供所有索引的大小。现在我想求所有大小的和,即0+2+1+1,然后与另一个整数相乘。可能吗?请帮助我,因为我没有哈希映射的经验


编辑:写在顶部的尺寸(即4)不是我需要的尺寸。这个大小基本上是有多少个索引的大小,有4个。但是,我需要以下大小的总和,即如果索引2中有4个值,那么总数将为6

int numberToMultiply = 0;
int total = 0;
for (String key : map.keySet()) {
   total = total + map.get(key).size()
}
 int ans = total*numberToMultiply

你可以试着跟着snipet

int numberToMultiply = 0;
int total = 0;
for (String key : map.keySet()) {
   total = total + map.get(key).size()
}
 int ans = total*numberToMultiply

从HasMap stringListMap中提取值

for (String k : values.keySet())
{
   // this will get you the size i.e. 0, 2, 1 which is the element of 
   // stringListMap HashMap, use it the way you want.
    values.get(k);
}

从HasMap stringListMap中提取值

for (String k : values.keySet())
{
   // this will get you the size i.e. 0, 2, 1 which is the element of 
   // stringListMap HashMap, use it the way you want.
    values.get(k);
}

事实上,这个问题相当令人困惑。你应该把你的具体问题转化为一个问题。事实上,这个问题相当令人困惑。你应该考虑你的具体问题,并尝试将其转化为一个问题。