[英]how to get the count of particular object in a List?
i want to get the count of the particular object in List我想获取 List 中特定对象的计数
AgentSumBeans obj=new AgentSumBeans();
while(rs.next())
{
obj.setIrctcIdCreatedDate(rs.getString(1));
obj.setIsevaProOpted(rs.getString(2));
}
list.add(obj);// first object
AgentSumBeans obj2=null;
while(rs3.next())
{
obj2=new AgentSumBeans();
obj2.setAmonthyear(rs3.getString(1));
obj2.setAnoOfTkts(rs3.getInt(2));
obj2.setAbookingAmount(rs3.getInt(3));
obj2.setAavgAmount(rs3.getInt(4));
obj2.setAperDayTkts(rs3.getInt(5));
list.add(obj2);// i will be getting more than one object here
}
how to find how many obj2
objects got created ?如何找到创建了多少
obj2
对象?
Try to replace while
loop to for
loop with counter - and it's the simplest solution, i think.尝试用计数器替换
while
循环到for
循环 - 我认为这是最简单的解决方案。
Or create counter before while
loop.或者在
while
循环之前创建计数器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.