如何获取列表中特定对象的计数?

时间:2017-09-01 08:54:51

标签: java arraylist

我想获取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

            }  

如何查找创建了多少obj2个对象?

1 个答案:

答案 0 :(得分:1)

尝试用计数器替换while循环到for循环 - 我认为这是最简单的解决方案。

或者在while循环之前创建计数器。