Java:计算HashMap中的项目总数< String,ArrayList< String>> [英] Java: count the total number of items in a HashMap<String, ArrayList<String>>

查看:121
本文介绍了Java:计算HashMap中的项目总数< String,ArrayList< String>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 HashMap< String,ArrayList< Item>> ,有没有办法计算地图中所有列表中的项目总数而不去通过所有列表?

I have this HashMap<String, ArrayList<Item>> , is there a way to count the total number of items in all the Lists in the Map without going through all Lists?

或者我应该遍历地图和所有列表吗?

Or should I iterate through the Map and along all lists ?

推荐答案

您可能希望查看 Google Guava 并使用Multimap 而不是那个。 Multimap.size()方法将给出你想要的答案。

You might want to see Google Guava and use Multimap instead of that. The Multimap.size() method will give the answer you want.

这篇关于Java:计算HashMap中的项目总数&lt; String,ArrayList&lt; String&gt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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