简体   繁体   English

从地图内部检索arraylist

[英]retrieving the arraylist from inside map

I have an query , I have an array list that conatain different arraylist inside as shown below 我有一个查询,我有一个数组列表,其中包含不同的arraylist,如下所示

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 现在的查询是我将最终列表放在地图中,因此reportmap本身就是一个arraylist,其中包含两个不同的arraylist

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. 现在,我的查询是我必须对BBBB中标头为AAAA的那些计数,以及对标头为BBBB中的Payment的那些计数,请告知如何实现。

Iterate through the List , check each element and count . 遍历List ,检查每个元素并计数。 And please follow Java coding and naming conventions . 并且请遵循Java编码和命名约定

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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