HashMap with multiple values under the same key

前端 未结 22 1888
旧时难觅i
旧时难觅i 2020-11-22 06:49

Is it possible for us to implement a HashMap with one key and two values. Just as HashMap?

Please do help me, also by telling (if there is no way) any other way to

22条回答
  •  旧时难觅i
    2020-11-22 07:17

    String key= "services_servicename"
    
    ArrayList data;
    
    for(int i = 0; i lessthen data.size(); i++) {
        HashMap servicesNameHashmap = new HashMap();
        servicesNameHashmap.put(key,data.get(i).getServiceName());
        mServiceNameArray.add(i,servicesNameHashmap);
    }
    

    I have got the Best Results.

    You just have to create new HashMap like

    HashMap servicesNameHashmap = new HashMap();
    

    in your for loop. It will have same effect like same key and multiple values.

提交回复
热议问题