技术交流群: 233513714
public LinkedHashMap<String, List<TPhoneModel>> queryPhoneList(List<TPhoneModel> list) {LinkedHashMap<String, List<TPhoneModel>> map = new LinkedHashMap<>();for (TPhoneModel li : list) {
//将需要归类的属性与map中的key进行比较,如果map中有该key则添加bean如果没有则新增keyif (map.containsKey(li.getAnotherName())) {
//取出map中key对应的list并将遍历出的bean放入该key对应的list中ArrayList<TPhoneModel> templist = (ArrayList<TPhoneModel>) map.get(li.getAnotherName());templist.add(li);} else {
//创建新的listArrayList<TPhoneModel> temlist = new ArrayList<TPhoneModel>();temlist.add(li);map.put(li.getAnotherName(), temlist);}}return map;}