简体   繁体   中英

retrieving the arraylist from inside map

I have an query , I have an array list that conatain different arraylist inside as shown below

List<abcInfo> abcabcdata = new ArrayList<abcInfo>(); //first arraylist

abcInfo abcdeed = new abcInfo();
        abcdeed.setHeader("AAAA");
        abcdeed.setabcdata(getNormalFuturesFeedList()); //List<FuturesFeedObject> it contains another arraylist
        abcabcdata.add(abcdeed);

        abcInfo abcdgen= new abcInfo();
        abcdgen.setHeader("BBBB");
        abcdgen.setabcdata(getabcdgenList()); //this method reurn arraylist, it contains list inside another arraylist
        abcabcdata.add(abcdgen);

Now the query is I am putting the final list in a map, so reportmap is itself an arraylist that contain two different arraylist inside it

HashMap<String, Object> abcdata = new HashMap<String, Object>();
        abcdata.put("YTRE", abcabcdata);

And finally I am retieving this array list on the basis of key

List<abcInfo> listWDownNoticesInfo = (ArrayList<abcInfo>)abcdata.get("YTRE");

Now my query is that I have to make a count of those whose header was AAAA and count of those whose header was Payment in BBBB please advise how to achieve this.

Iterate through the List , check each element and count . And please follow Java coding and naming conventions .

List<abcInfo> listWDownNoticesInfo = (ArrayList<abcInfo>)abcdata.get("YTRE");
Iterator<abcInfo> itr = listWDownNoticesInfo .iterator();
int countA = 0;
int countB = 0;
while(itr.hasNext()) {
    abcInfo element = itr.next();
    if(element.getHeader().equals("AAAA")){
      countA++;
    }
    if(element.getHeader().equals("BBBB")){
      countB++;
    }
}
int count1 = 0;
int count2 = 0;
for(abcInfo obj:listWDownNoticesInfo){

 if(obj.getHeader.equals("AAA")
   count1++;
 else  if(obj.getHeader.equals("BBB")
   count2++;

}

System.out.println("Header AAA count:"+count1);
System.out.println("Header BBB count:"+cpunt2);

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