Retrieve all values from HashMap keys in an ArrayList Java

前端 未结 9 1382
野性不改
野性不改 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 14:51

    Suppose I have Hashmap with key datatype as KeyDataType and value datatype as ValueDataType

    HashMap list;
    

    Add all items you needed to it. Now you can retrive all hashmap keys to a list by.

    KeyDataType[] mKeys;
    mKeys=list.keySet().toArray(new KeyDataType[list.size()]);
    

    So, now you got your all keys in an array mkeys[]

    you can now retrieve any value by calling

     list.get(mkeys[position]);
    

提交回复
热议问题