现在的位置: 首页 > 综合 > 正文

检测list内有几组相同元素

2014年03月27日 ⁄ 综合 ⁄ 共 1003字 ⁄ 字号 评论关闭

/***************************************************************************
     * 把传入的list按照receiveBranchId分组 分好的组再存入 另一个List[],list[]每个元素就是一个包的所有票据
     *
     * @param list  要分组的List
     */

    public static List[] MakeBagDaobyHand(List list) {
        Set set = new HashSet();
        for (int i = 0; i < list.size(); i++) {
            //TBill tb = (TBill) list.get(i);
        ///    int receiveBranchId = tb.getReceivebranchId().intValue();
        //    set.add(receiveBranchId);
            int a = (Integer)list.get(i);
            set.add(a);
        
        }
        List[] arr = new ArrayList[set.size()];// 每个元素是相同receiveBranchId的TBill
        Iterator it = set.iterator(); // Set里保存相同的receiveBranchId
        
        int count = 0;// 计算Set遍历set的ID
        while (it.hasNext()) { // 遍历
            int rid = (Integer) it.next();
            arr[count] = new ArrayList();
            for (int i = 0; i < list.size(); i++) {
                int listId = (Integer) list.get(i);
                if (rid == listId) {
                    
                    
                    arr[count].add(rid);
                }
            }
            count++;
        }
        return arr;
    }

抱歉!评论已关闭.