Android 获取所有Hashmap索引大小的总和
我正在实现一个逻辑,其中我必须将某个整数乘以其中hashmap值的大小。不幸的是,我无法做到这一点。附件中的图片可以为我提供所有索引的大小。现在我想求所有大小的和,即0+2+1+1,然后与另一个整数相乘。可能吗?请帮助我,因为我没有哈希映射的经验Android 获取所有Hashmap索引大小的总和,android,hashmap,Android,Hashmap,我正在实现一个逻辑,其中我必须将某个整数乘以其中hashmap值的大小。不幸的是,我无法做到这一点。附件中的图片可以为我提供所有索引的大小。现在我想求所有大小的和,即0+2+1+1,然后与另一个整数相乘。可能吗?请帮助我,因为我没有哈希映射的经验 编辑:写在顶部的尺寸(即4)不是我需要的尺寸。这个大小基本上是有多少个索引的大小,有4个。但是,我需要以下大小的总和,即如果索引2中有4个值,那么总数将为6 int numberToMultiply = 0; int total = 0; for (S
编辑:写在顶部的尺寸(即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);
}
事实上,这个问题相当令人困惑。你应该把你的具体问题转化为一个问题。事实上,这个问题相当令人困惑。你应该考虑你的具体问题,并尝试将其转化为一个问题。