码迷,mamicode.com
首页 > 其他好文 > 详细

List去除重复元素

时间:2016-04-26 19:07:58      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

list:[{"ss":123,"dd":234,"dd":234},{"mm":99,"ff":oo,"ff":oo}]

这种形式的:

 1 List<Map<String,Object>> newList 
 2 = new ArrayList<Map<String,Object>>();
 3         Set<Set<String>> keysSet = new HashSet<Set<String>>();
 4         for(Map<String, Object> map : list){
 5             Set<String> keys = map.keySet();
 6             int beforeSize = keysSet.size();
 7             keysSet.add(keys);
 8             int afterSize = keysSet.size();
 9             if(afterSize == beforeSize + 1){
10                 newList.add(map);
11             }
12         }
13 return newList;

list:[{groupId=122}, {groupId=124}, {groupId=135}, {groupId=91},

 {groupId=109}, {groupId=124}, {groupId=135}, {groupId=126},

{groupId=127}, {groupId=133}, {groupId=134}, {groupId=151}]

 这种形式的:

 1 List<Map<String,Object>> newList 
 2 = new ArrayList<Map<String,Object>>();
 3         Set<Map<String,Object>> mapSet
 4        = new HashSet<Map<String,Object>>();
 5         for(Map<String, Object> map : list) {
 6             mapSet.add(map);
 7         }
 8 Iterator<Map<String, Object>> iteratormap=mapSet.iterator();
 9    while(iteratormap.hasNext()){
10          newList.add(iteratormap.next());
11    }
12 return newList;

 

List去除重复元素

标签:

原文地址:http://www.cnblogs.com/cxj-qldxmf/p/5435991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!