2013-08-02 132 views
-2

我想從HashMap獲取properteis。如何從HashMap獲取值?

HashMap<String, Object> getProperties() 

我想獲得屬性是正確的。

+1

值並ú谷歌夥計? – KOTIOS

+0

請在請求之前嘗試谷歌! – TN888

+0

我做了,但我無法找到任何好的答案,我很新的android .. – mstfdz

回答

3

例子:

HashMap<String, String> newMap = new HashMap<String, String>(); 
newMap.put("property", "shhh_secret"); 
String value = newMap.get("property"); 

Set s = newMap.keySet(); 
for (Iterator iter = s.iterator(); iter.hasNext()) { 
    newMap.get(s); 
} 

Iterator iter = newMap.keySet().iterator(); 
while (iter.hasNext()) { 
      ... 
} 

Source and more examples

0

這將有助於讀取HashMap..Simple例如

HashMap<Integer, String> hm = new HashMap<Integer, String>(); 
    hm.put(1, "One"); 
    hm.put(2, "Two"); 
    hm.put(3, "Three"); 

    Set st = hm.entrySet(); //hm.keySet(); 
    for(Iterator itr = st.iterator(); itr.hasNext();) 
    { 
     //hm.get(st); 
     System.out.println(itr.next()); 
    }