将list中的元素按照属性分类成树状的map
生活随笔
收集整理的這篇文章主要介紹了
将list中的元素按照属性分类成树状的map
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
技術交流群:?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;}
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;}
?
轉載于:https://www.cnblogs.com/cnndevelop/p/6373097.html
總結
以上是生活随笔為你收集整理的将list中的元素按照属性分类成树状的map的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2 django系列之django分页与
- 下一篇: zendstudio快捷键收录