---
title: "list中map里数字合计"
author: "ddandyy"
date: "2008-10-28T14:03:55Z"
tags: []
slug: "list-map"
draft: false
lastmod: "2008-10-28T14:03:55Z"
id: 258961
url: "https://ddandyy.iteye.com/blog/258961"
---

多年之前写的 突然翻到了 留念..........



```java
    /**
     * 合計
     * @param selectList データリスト
     * @param key カラム名称
     * @return データ
     */
	public static Map getAmount(List selectList, String[] key) {
        Map param = new HashMap();
        if (selectList!=null) {
            if (selectList.size() > 0) {
                for (int i=0; i<key.length; i++) {
                    String str = key[i];
                    param.put(str+"_amount",new BigDecimal(0));
                }
                Iterator list = selectList.iterator();
                while(list.hasNext()) {
                    Map map = (Map)list.next();
                    for (int i=0; i<key.length; i++) {
                        String strin = key[i];
                        BigDecimal num = (BigDecimal) param.get(strin+"_amount");
                        Object obj = map.get(strin);
                        if (obj != null) {
                            num = num.add(new BigDecimal(String.valueOf(obj)));
                        }
                        param.put(strin+"_amount", num);
                    }
                }
            }
        }
		return param;
	}
```