java中hashmap獲取list

首先咱們將list存入到map中,如何快速獲取list呢java

我在網站找到兩種方式網站

HashMap<String, String>hm=new HashMap<String, String>();
方式1
Iterator iterator = hm.keySet().iterator();
while(iterator.hasNext()) {
System.out.println(hm.get(iterator.next()));
}
方式2
Set set = hm.entrySet() ;
java.util.Iterator it = hm.entrySet().iterator();
while(it.hasNext()){
java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
// entry.getKey() 返回與此項對應的鍵
// entry.getValue() 返回與此項對應的值
System.out.println(entry.getValue());
}對象

可是我只想獲取其中的一個對象 ,這樣都遍歷很麻煩get

最後我直接這樣寫,是能夠獲取的
it

 list=(List<model>) result.get("list");
List

相關文章
相關標籤/搜索