java对重复数据的处理操作(加上标识区分重复)
2013-10-09 10:13
281 查看
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; public class Main { /** * @param args */ public static void main(String[] args) { Map map1 = new HashMap(); Map<String,Integer> map2 = new HashMap<String,Integer>();//存相同的value出现了几次 Map map3 = new HashMap(); map1.put("info0", "info1"); map1.put("info1", "info1"); map1.put("info2", "info3"); map1.put("info3", "info4"); map1.put("info4", "info5"); map1.put("info5", "info6"); Set key = map1.keySet(); Iterator it = key.iterator(); String[] a = new String[map1.size()]; int b = 0; int count = 0; while(it.hasNext()){ a[b++] = (String) map1.get(it.next()); } for(int i = 0; i < a.length; i++){ String str = a[i]; for(int j = 0; j < a.length; j++){ if(str.equals(a[j])){ count++; } } map2.put(str, count);//map里如果key相同 会自动覆盖之前的value count = 0;//统计一次归一次0 } Set key1 = map2.keySet(); Iterator it1 = key1.iterator(); while(it1.hasNext()){ String temp = (String) it1.next(); int mapCount = (int) map2.get(temp); if(mapCount != 1){ for(int i = 1; i <= mapCount; i++){ map3.put(temp + "_" + i,temp + "("+i+")" ); } }else{ map3.put(temp, temp); } } System.out.println(map3); } }
相关文章推荐
- elasticsearch__3__java操作之Facets 数据分组统计处理
- java操作处理Excel表格数据
- 最全面的Java字节byte操作,处理Java基本数据的转换及进制转换操作工具,流媒体及java底层开发项目常用工具类
- Java字节流和字符流的区别 (方法区别 操作基本单元区别 操作方式区别 处理数据类型区别) 之个人总结
- 对于需要根据客户操作更新数据的情况的去重复处理
- java处理导入Excel数据重复数据,整理后在导入
- java的文件操作处理时间数据
- 最全面的Java字节byte操作,处理Java基本数据的转换及进制转换操作工具
- JFinal中java如何处理数据库查询出的重复数据
- JAVAWEB开发之JDBC详解(连接操作数据库、处理大数据、批处理)
- java对前台增删改操作后数据的处理方法
- 华为2013机试题Java解(重复字符串的处理操作)
- JavaWeb之DBUtils(一)QueryRunner类对数据表的增、删、查(8种结果集处理方式)、改操作
- java操作txt或xls文件批量导入数据
- Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
- sql重复数据处理
- 字符串处理是许多程序中非常重要的一部分,它们可以用于文本显示,数据表示,查找键和很多目的.在Unix下,用户可以使用正则表达式的强健功能实现这些 目的,从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础
- java 操作xml数据 转换byte spring源码分享
- MySQL 处理重复数据