1 public static void fenZu(List<FilePackageModel> list, Map<String, List<FilePackageModel>> map) {//map是用來接收分好的組的 2 if (null == list || null == map) { 3 return; 4 } 5 6
7 String key; 8 List<FilePackageModel> listTmp; 9 for (FilePackageModel val : list) { 10 key = val.getPkgclassifythree();//按這個屬性分組,map的Key 11 listTmp = map.get(key); 12 if (null == listTmp) { 13 listTmp = new ArrayList<FilePackageModel>(); 14 map.put(key, listTmp); 15 } 16 listTmp.add(val); 17 } 18 }
傳進來一個list集合,把list的元素按某一個屬性分組。傳進來的map用於接收分好的組。每一個key對應一個相同屬性的List分組。