码迷,mamicode.com
首页 > 编程语言 > 详细

group by java实现

时间:2016-12-28 02:12:55      阅读:282      评论:0      收藏:0      [点我收藏+]

标签:group   key   contain   value   mount   arraylist   amount   hashmap   system   

public static void abc(List list,String... sortName) throws Exception{
Map<String,List<Object>> tMap = new HashMap<String,List<Object>>();
for(Object t : list){
String filedKey ="";
for(String filedName : sortName){
Field field = t.getClass().getDeclaredField(filedName);
filedKey = field.get(t)+","+filedKey;
System.out.println("filedName======"+filedKey);
}

if(tMap.containsKey(filedKey)){
tMap.get(filedKey).add(t);
}else{
List tList1 = new ArrayList();
tList1.add(t);
tMap.put(filedKey,tList1);
}
}
for(Map.Entry<String,List<Object>> entry : tMap.entrySet()){
int billAmount = 0;
TestPolNo polNo = new TestPolNo();
System.out.println("Key = " + entry.getKey());
for(Object t : entry.getValue()){
System.out.println(t.toString());
billAmount+= t.getClass().getDeclaredField("bill").getInt(t);
//t.getBill();
}
polNo.setPolNo(entry.getKey());
polNo.setBillAmount(billAmount);
System.out.println(polNo.toString());
}


}

group by java实现

标签:group   key   contain   value   mount   arraylist   amount   hashmap   system   

原文地址:http://www.cnblogs.com/jingRegina/p/6228012.html

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