技术交流群: 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如果没有则新增key
if (map.containsKey(li.getAnotherName())) {
        //取出map中key对应的list并将遍历出的bean放入该key对应的list中 ArrayList
<TPhoneModel> templist = (ArrayList<TPhoneModel>) map.get(li.getAnotherName()); templist.add(li); } else {
        //创建新的list ArrayList
<TPhoneModel> temlist = new ArrayList<TPhoneModel>(); temlist.add(li); map.put(li.getAnotherName(), temlist); } } return map; }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2021-11-24
相关资源
相似解决方案