Reputation:
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.
Upvotes: 0
Views: 76
Reputation: 49432
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++;
}
}
Upvotes: 1
Reputation: 40358
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);
Upvotes: 0