public static void main(String[] args){
List<Map<String,Object>> list1 = new ArrayList<Map<String,Object>>();
Map<String,Object> map1 = new HashMap<String,Object>();
Map<String,Object> map2 = new HashMap<String,Object>();
Map<String,Object> map3 = new HashMap<String,Object>();
map1.put("张三", new Integer(92));
map2.put("李四", new Integer(85));
map3.put("张三", new Integer(90));
list1.add(map1);
list1.add(map2);
list1.add(map3); Map<String,Object> mapAll = new HashMap<String,Object>();
     //Map<String,Object> mapAll = new LinkedHashMap<String,Object>();// 保证循序
        for(Map<String,Object> map:list1){
for(Map.Entry<String, Object> entry:map.entrySet()){
String name = entry.getKey();
Object score = entry.getValue();
Object scoreAll = mapAll.get(entry.getKey());
if(scoreAll == null){
mapAll.put(name, score);
}else{
scoreAll = new Integer((((Integer)scoreAll).intValue() + ((Integer)score).intValue()));
mapAll.put(name, scoreAll);
}
}
} for(Map.Entry<String, Object> entry:mapAll.entrySet()){
//如果需要将map再做list,在这里处理
System.out.println(entry.getKey() + "," + entry.getValue());
} }

List<Map<String, Integer>> 同key的value全部累加合并的更多相关文章

  1. Map<String,Integer>acount字符串出现的次数

  2. Java中Map根据键值(key)或者值(value)进行排序实现

    我们都知道,java中的Map结构是key->value键值对存储的,而且根据Map的特性,同一个Map中 不存在两个Key相同的元素,而value不存在这个限制.换句话说,在同一个Map中Ke ...

  3. List<Map<String, Object>>集合中获取某个key并转换为List<Integer>集合

    package com.codyy.sso.controller.yuanqu; import java.util.ArrayList; import java.util.HashMap; impor ...

  4. JAVA中对List<map<String,Object>>根据map某个key值进行排序

    方法compareTo()比较此对象与指定对象的顺序.如果该对象小于.等于或大于指定对象,则分别返回负整数.零或正整数.返回整数,1,-1,0:返回1表示大于,返回-1表示小于,返回0表示相等. 普通 ...

  5. 取出List<Map<String,Object>>里面Map的key:value值

    1.取出Map其中一个属性的值 Map map = new HashMap(); map.put("key1", "value1"); map.put(&quo ...

  6. Map<String,Object>接收参数,Long类型降级为Integer,报类型转换异常

    前言 今天看群里小伙伴问了一个非常有意思的问题: 使用 Map<String,Object> 对象接收前端传递的参数,在后端取参时,因为接口文档中明确该字段类型为 Long ,所以对接收的 ...

  7. list和list<map<String,object>>比较,不存在map的key赋值

    package com; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDa ...

  8. Map<String, String> map按key值排序

    private static String buildMd5Params(Map<String, String> map) { StringBuilder result = new Str ...

  9. 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历

    分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...

随机推荐

  1. 顶点与UV

    1.顶点坐标和UV坐标是三维模型重要的两个坐标系统. 2.什么是UV?UV分别是图像在显示器水平和垂直方向上坐标,值在 0 - 1 之间 ,即水平方向的第 U 个做像素/图片宽度,垂直方向的第 V 个 ...

  2. English trip V1 - 3.What Would you Like? Teacher:Lamb Key: would like to

    In this lesson you will learn to talk about fast food and health. would = will 的过去式 STARTER 1.Tell y ...

  3. 4-14-17 JavaScript知识点总结(包括JOSN, ajax等,来源w3c)

    JavaScript 也称 ECMAScript as "JavaScript" It is designed to run as a scripting language in ...

  4. 1月24日 ruby基础3部分 Numeric, Array已学。

    <div style="background:lightblue"> 第12章 数值类 12.1 数值的构成 Numeric-> Integer-> Fix ...

  5. Working routine CodeForces - 706E (链表)

    大意: 给定矩阵, q个操作, 每次选两个子矩阵交换, 最后输出交换后的矩阵 双向十字链表模拟就行了 const int N = 1500; int n, m, q; struct _ { int v ...

  6. Professional layer CodeForces - 1103D (状压,gcd)

    大意: 给定$n$元素序列$a$, 现在想要让$gcd(a_1,a_2,...,a_n)=1$. 对于每个$a_i$可以除以一个不超过$k$的因子, 代价为$e_i$, 假设一共选择了$x$个元素去除 ...

  7. Serega and Fun CodeForces - 455D (分块 或 splay)

    大意:给定n元素序列, 2种操作 将区间$[l,r]$循环右移1位 询问$[l,r]$中有多少个等于k的元素 现在给定q个操作, 输出操作2的询问结果, 强制在线 思路1: 分块 每个块内维护一个链表 ...

  8. Cron\CronExpression::setPart("24")

    利用laravle实现定时器的功能的时候,报错说:Cron\CronExpression::setPart("24"). 后来发现是时间设置的问题,他不能设置("24:0 ...

  9. Docker 构建 redis 集群

    安装docker 1.yum install docker 方法一: 1. docker pull redis 2.docker run -d --name redis-1 -p 7001:6379 ...

  10. UVA-1533 Moving Pegs (路径寻找问题)

    Description   Venture MFG Company, Inc. has made a game board. This game board has 15 holes and thes ...