如何从HashMap获取值?

时间:2013-08-02 11:57:14

标签: hashmap

我想从HashMap获取属性。

HashMap<String, Object> getProperties()

我想获得真实的属性。

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

答案 2 :(得分:0)

这将有助于从HashMap中读取值。简单示例

    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());
    }