我定义了一个hashmap如下
HashMap<String, List<String>> hashmap = new HashMap<String, List<String>>();
我可以通过
获取其内容Set<Map.Entry<String, List<String>>> keys = hashmap.entrySet();
for (Map.Entry<String,List<String>> entry : hashmap.entrySet()) {
String key = entry.getKey();
List<String> thing = entry.getValue();
System.out.println (key);
System.out.println (thing);
}
但是,我想知道:
string[0]
等同样的方式答案 0 :(得分:2)
假设地图中存在String key = "str";
。你可以:
int mapSize = hashmap.size(); // get the map's size
List<String> list = hashmap.get("str"); // get a list for a key
String first = hashmap.get("str").get(0); // get a string in a list
int listSize = hashmap.get("str").size(); // get the size of a list
char ch = hashmap.get("str").get(0).charAt(0); // get a char of a string in a list in the map
答案 1 :(得分:1)