How to convert list to HashMap

How can I convert this:

Map<String,Integer> itemsBought

So I can add it to the ArrayList as follows:

public void add(String prd,int qty){
        orderList.add(new Order(prd,qty));
}

There are other solutions:

hashMap.keySet().toArray(); 
hashMap.values().toArray();

Thank you first

Solution

for (Entry<String,Integer> entry : itemsBought.entrySet()) {
for (Entry<String,Integer> entry : itemsBought.entrySet()) {
    orderList.add(new Order(entry.getKey(),entry.getValue()));
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>