展开全部
package 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;
}
}