Java: how to convert HashMap to array

前端 未结 12 1932
时光取名叫无心
时光取名叫无心 2020-11-29 16:36

I need to convert a HashMap to an array; could anyone show me how it\'s done?

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 17:17

    If you want the keys and values, you can always do this via the entrySet:

    hashMap.entrySet().toArray(); // returns a Map.Entry[]
    

    From each entry you can (of course) get both the key and value via the getKey and getValue methods

提交回复
热议问题