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
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("unchecked")
public class TestList {//koukouGroup two one seven seven seven one two有不明白的进来问
public static Listturn2Union(List inList){
ListoutList = new ArrayList ();//用于返回list
MapdanMaps = new HashMap ();//用于记录单位和金额如果金额不是整数就把Integer改成double啥的
ListdanKeys = new ArrayList ();//用于记录单位
for (int i = 0; i < inList.size(); i++) {
Map inMap = inList.get(i);
String oneDan = inMap.get("danwei").toString();//取出单位
if(danMaps.containsKey(oneDan)){
danMaps.put(oneDan, danMaps.get(oneDan)+Integer.valueOf(inMap.get("jine").toString()));
}else{
danMaps.put(oneDan, Integer.valueOf(inMap.get("jine").toString()));
danKeys.add(oneDan);
}
}
for (int i = 0; i < danKeys.size(); i++) {
Map map = new HashMap();
map.put("danwei",danKeys.get(i));
map.put("jine",danMaps.get(danKeys.get(i)));
outList.add(map);
}
return outList;
}
public static void main(String[] args) {
Listlist = new ArrayList ();
Map map1 = new HashMap();
map1.put("danwei", "美元");
map1.put("jine", "1000");
list.add(map1);
Map map2 = new HashMap();
map2.put("danwei", "日元");
map2.put("jine", "2000");
list.add(map2);
Map map3 = new HashMap();
map3.put("danwei", "日元");
map3.put("jine", "1000");
list.add(map3);
Map map4 = new HashMap();
map4.put("danwei", "欧元");
map4.put("jine", "1500");
list.add(map4);
ListtList = turn2Union(list);
for (int i = 0; i < tList.size(); i++) {
Map map = tList.get(i);
System.out.println(map.get("danwei")+":"+map.get("jine"));
}
}
}
netbeans eclipse
不好说啊,你的map里面的key是什么?