list<javabean>集合

 List<LeaveApply> list = new ArrayList<LeaveApply>();

   LeaveDAO leaveDao = new LeaveDAO();
   leaveApply = leaveDao.getLeaveApply(wfid);
list.add(leaveApply);

详细的例子:

package cn.zhangao;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry; public class ListGroup {
    public static void main(String[] args) {
        List<JavaBean> list = new ArrayList<JavaBean>();
        list.add(new JavaBean("来源A", 100));
        list.add(new JavaBean("来源B", 200));
        list.add(new JavaBean("来源C", 300));
        list.add(new JavaBean("来源B", 6600));
        list.add(new JavaBean("来源A", 99800));
        List<JavaBean> groupList = getListByGroup(list);
        for (JavaBean bean : groupList) {
            System.out.print(bean.getGroup() + "        ");
            System.out.println(bean.getMoney());
        }
    }
    private static List<JavaBean> getListByGroup(List<JavaBean> list) {
        List<JavaBean> result = new ArrayList<JavaBean>();
        Map<String, Integer> map = new HashMap<String, Integer>();
        for (JavaBean bean : list) {
            if (map.containsKey(bean.getGroup())) {
                map.put(bean.getGroup(), map.get(bean.getGroup()) + bean.getMoney());
            } else {
                map.put(bean.getGroup(), bean.getMoney());
            }
        }
        for (Entry<String, Integer> entry : map.entrySet()) {
            result.add(new JavaBean(entry.getKey(), entry.getValue()));
        }
        return result;
    }
}
class JavaBean {
    private String group;
    private int money;
    public JavaBean() {
    }
    public JavaBean(String group, int money) {
        this.group = group;
        this.money = money;
    }
    public String getGroup() {
        return group;
    }
    public void setGroup(String group) {
        this.group = group;
    }
    public int getMoney() {
        return money;
    }
    public void setMoney(int money) {
        this.money = money;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>