简体   繁体   中英

How to convert JavaBean contains List to Map in java

public class MyAgreementList {
    private String name;

    private List<MyAgreement> agreementList;

    public List<MyAgreement> getAgreementList() {
        return agreementList;
    }

    public void setAgreementList(List<MyAgreement> agreementList) {
        this.agreementList = agreementList;
    }


}

I want to convert MyAgreementList to Map,anyone can help me? The result I want is that:the Map have two keys : name,agreementList,and the List value can not be lost

Is there any framework can support this?

psudocode : iterate the list and get agreement id and add as key else maintain some counter for key.Hope this helps

for(MyAgreement mya : agreementList){
      map.put(mya.getId(),mya);
      //maintain a counter say counter
       //map.put(counter++,mya);
     }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM