java分组方法

来源:互联网 发布:淘宝装修图 编辑:程序博客网 时间:2024/05/02 02:46
public static Map group(List<DeviceGps> target)
02  {
03  Map<Integer, List<DeviceGps>> gpsMap=new HashMap<Integer, List<DeviceGps>>();
04        for (int i = 0; i < target.size(); i++)
05        
06         DeviceGps myObject = target.get(i); 
07         int operatorID=myObject.getOperator_id();
08         List<DeviceGps> gpsList = gpsMap.get(operatorID);
09         if(gpsList==null) {
10          gpsList = new ArrayList<DeviceGps>();
11          gpsMap.put(operatorID, gpsList);
12         }
13         gpsList.add(myObject);
14        }
15  return gpsMap;
16  }
原创粉丝点击