[英]Retrieving information from 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]
,等等 假設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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.