java - 将地图的地图转换为java中的地图列表
问题描述
我有一个java地图,
Map<Date, Map<String, Integer>> dateTeamCountMap;
我想转换上面给出值的地图
{28-09-2018={India=14,Australia=16}, 31-09-2018={India=13,Australia=11}}
进入格式对象列表
{{Date:28-09-2018, India:14, Australia:26},{Date:31-09-2018, India:13, Australia:11}}
对不起,我是stackoverflow的新手。如果我错了,请纠正我的问题。谢谢。
我无法创建一个通用列表,因为我总是不知道团队的数量。
解决方案
这样的事情怎么样?
ArrayList<Map<String, String>> list = new ArrayList<Map<String, String>>();
dateTeamCountMap.forEach((date, nestedMap) -> {
Map<String, String> temp = new HashMap<String, String>();
temp.put("Date",date);
nestedMap.forEach((team, count) -> {
temp.put(team,count);
});
list.add(temp);
});
如果您有一个代表类{Date:28-09-2018, India:14, Australia:26}
,那么您也可以创建List<YourClass>
。
推荐阅读
- sql - 如何在 Azure sql 中将整数列转换为逗号分隔的行
- asp.net - 如何解决这个丢失的水晶报告程序集?
- python - 如何在 Python 中修复 selenium“DevToolsActivePort 文件不存在”异常
- javascript - Javascript - 模板文字 - 三元运算
- javascript - 删除倒数计时器中的 0
- angular - angular 5 动态组件 未找到组件工厂
- python - 参数“弱”或“强”对 scipy.sparse.csgraph.connected_components 有什么作用?
- python-3.x - rabbitpy - 在上下文管理器之外未引发异常
- c# - CreateUploadSession() 因 IE11 和 Edge 的请求而失败
- vb.net - VB.Net Excel 透视过滤器