java - 将元素添加到 HashMap 中的 ArrayList
问题描述
如何将元素添加到 HashMap 中的 ArrayList?
这是一个问题,我问过自己很多次,解决后忘记了。我想很多人都有相同的,所以这里是一个简单的答案。
// Example
HashMap<String, ArrayList<String>> someElements = new HashMap<String, ArrayList<String>>();
解决方案
// fill the HashMap with the key that you need
// initiate it with an empty ArrayList
someElements.put("keyString" , new ArrayList<String>());
// Later when wanting to add an element to the ArrayList of a key use
someElements.get("keyString").add("TheStringValue");
推荐阅读
- view - 响应 REST API 获取 admin_view 的权限是什么:https://www.googleapis.com/admin/directory/v1/users?viewType=admin_view'
- python - Pandas Dataframe Yahoo Finance 检查交易量是否符合标准
- java - Openssl,Java:无法解密长消息
- javascript - 如何获得十六进制颜色主类别(不确切名称)
- android - Eclipse - 错误“Android 包生成器”
- powerbuilder - POST setitem 不在数据窗口中设置值
- c++ - 包括 winmm.lib 不起作用
- sublimetext3 - 使用 SublimeText3,如何打开所有同名文件
- c++ - 有没有办法为容器类型创建运算符/函数重载
- python - 我们应该使用元组还是列表作为 index_together