java - constrcut hashmap form database rows -


this question has answer here:

i have following rows when query

id listingid    campaignid    budget    clicks 1  bvfbdvfdv      xxx          500        20 2  ijioiooij      xxx          500        13 3  awstetsee      xxx          500        09 4  gccgdcdcc      yyy          600        45 5  jjkhvnsdj      yyy          600        28 6  bvkljfvjv      zzz          1000       17 7  hejvejvek      ppp          690        23 8  vmfklvmkv      ppp          690        0 9  fnkvnfkvd      ppp          690        11 

how ever created entity class listingreport above rows , stored in list.

i need create hashmap<string>,list<listingreport>> ,

where key campaignid column of listingreport , listingreport rows corresponding same campaignid stored in list.

while iterating listingreport

where key campaignid column

while(listingreportiterator.hasnext()) { string key = listingreportobject.getcampaignid(); ..  } 

you can try code.

map<string, list<listingreport>> map = new hashmap<string, list<listingreport>>(); list<listingreport> list; listingreport listingreport; while (listingreportiterator.hasnext()) {     string key = listingreportobject.getcampaignid();      list = map.get(key);     if (list == null) {         list = new arraylist<listingreport>();         map.put(key, list);     }     // set values in listingreport object     listingreport = new listingreport();     // listingreport.setattributes      list.add(listingreport); } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -