-1

I have the following rows when I 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 i created entity class ListingReport for above rows as and stored in List.

I need to create the HashMap<String>,List<ListingReport>> ,

where key will be the CampaignId column of ListingReport and all ListingReport rows corresponding to same campaignId will be stored in List.

while iterating ListingReport

where the key will be the CampaignId column

while(ListingReportIterator.hasnext()) {
String key = ListingReportObject.getCampaignId();
..

}
Cœur
  • 37,241
  • 25
  • 195
  • 267
pavan
  • 334
  • 6
  • 20

1 Answers1

1

You can try this 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);
}
Naman Gala
  • 4,670
  • 1
  • 21
  • 55