Retrieve all values from HashMap keys in an ArrayList Java

前端 未结 9 1397
野性不改
野性不改 2021-01-31 14:21

Good day, this is kind of confusing me now(brain freeze!) and seem to be missing something. Have an ArrayList which i populate with a HashMap. now i put in my HashMap and arrayl

9条回答
  •  醉酒成梦
    2021-01-31 15:02

    Try it this way...

    I am considering the HashMap with key and value of type String, HashMap

    HashMap hmap = new HashMap();
    
    hmap.put("key1","Val1");
    hmap.put("key2","Val2");
    
    ArrayList arList = new ArrayList();
    
    for(Map.Entry map : hmap.entrySet()){
    
         arList.add(map.getValue());
    
    }
    

提交回复
热议问题