java 重复数据_java取List中重复的数据!

展开全部

56b31785c126f3ef16dad6d9c72e73d5.pngpackage acc.testJSON;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Map.Entry;

import java.util.Set;

public class AA {

public static void main(String[] args) {

List> list=new ArrayList>();

Map map2=new HashMap();

map2.put(1, "美元");

map2.put(2, "日元");

map2.put(3, "欧元");

map2.put(4, "日元");

map2.put(5, "人民币");

map2.put(10, "欧元");

list.add(map2);

32313133353236313431303231363533e58685e5aeb931333332626161

System.out.println("--------之前---------------");

for(int i=0;i

Map tempMap=list.get(i);

for(Entry e:tempMap.entrySet()){

System.out.println("K: "+e.getKey()+" v: "+e.getValue());

}}

System.out.println("---------------------开始处理--------------------------");

List> newList=new ArrayList>();

AA aa=new AA();

newList=aa.executMoedth(list);//如果有相同的

System.out.println("--------之后---------------");

for(int i=0;i

Map tempMap=newList.get(i);

for(Entry e:tempMap.entrySet()){

System.out.println(e.getValue()+":"+e.getKey());

}}

}

public List> executMoedth(List> list){

System.out.println("---------------------处理中--------------------------");

List> newList=new ArrayList>();

Map newMap=new HashMap();

for(int i=0;i

Map tempMap=list.get(i);//第i个list中的Map

for(Entry e1:tempMap.entrySet()){//map遍历

int tempi=0;

for(Entry e2:tempMap.entrySet()){//map遍历

if(e1.getValue().equals(e2.getValue())){//如果相等

if(!e1.equals(e2))

/* tempi++;

if(tempi>=1)*/

{

// newMap.remove(e1.getKey());//移除第一个添加的

int newValus=e1.getKey()+e2.getKey();//得到总钱数

String newKey=e1.getValue();

newMap.remove(e1.getValue());//干掉

newMap.remove(e2.getValue());//干掉

System.out.println("找到一个 已处理:"+newKey + newValus);

newMap.put(newKey,newValus);//新集合

}

//如果新集合里没有的

if(!newMap.containsKey(e1.getValue()))

newMap.put(e1.getValue(),e1.getKey());//新集合

}

}

}

newList.add(newMap);//新集合

}

return newList;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值