首页 > 编程语言 > 详细

group by java实现

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

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实现

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!