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. windows批处理命令

    前言 批处理文件(batch file)包含一系列 DOS命令,通常用于自动执行重复性任务.用户只需双击批处理文件便可执行任务,而无需重复输入相同指令.编写批处理文件非常简单,但难点在于确保一切按顺序 ...

  2. Redis分布式锁实现简单秒杀功能

    这版秒杀只是解决瞬间访问过高服务器压力过大,请求速度变慢,大大消耗服务器性能的问题. 主要就是在高并发秒杀的场景下,很多人访问时并没有拿到锁,所以直接跳过了.这样就处理了多线程并发问题的同时也保证了服 ...

  3. MySQL缓存机制

    对MySql查询缓存及SQL Server过程缓存的理解及总结 一.MySql的Query Cache 1.Query Cache   MySQL Query Cache是用来缓存我们所执行的SELE ...

  4. 此纳税人登记号已用于同一期间的交易方(交易方类型为 XXX 且交易方名称为 xxxx)。

    When updated Supplier's tax informations , System occurs a error:'This tax registration number is al ...

  5. 使用路径arc

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  6. Nginx 关于 location 的匹配规则详解

    有些童鞋的误区 1. location 的匹配顺序是“先匹配正则,再匹配普通”. 矫正: location 的匹配顺序其实是“先匹配普通,再匹配正则”.我这么说,大家一定会反驳我,因为按“先匹配普通, ...

  7. 微信公众号平台开发(二)信息的分类.md

    在上一篇博客中,我们只是简单地与微信服务器建立了连接,接下来就是从微信服务器中接收信息了.在SecurityController中,我定义了两个方法(get和post).Get方法是我们用来与微信服务 ...

  8. 深入理解MyBatis中的一级缓存与二级缓存

    http://blog.csdn.net/weixin_36380516/article/details/73194758   先说缓存,合理使用缓存是优化中最常见的,将从数据库中查询出来的数据放入缓 ...

  9. PHP:第二章——PHP中的for语句

    知识点一:for语句    语法格式:    for(expr1;expr2;expr3){        //代码块;    }     说明:     expr1:循环开始前,无条件的执行一次,并 ...

  10. SQL Server 调优系列基础篇 - 常用运算符总结

    前言 上一篇我们介绍了如何查看查询计划,本篇将介绍在我们查看的查询计划时的分析技巧,以及几种我们常用的运算符优化技巧,同样侧重基础知识的掌握. 通过本篇可以了解我们平常所写的T-SQL语句,在SQL ...