老师关于代码顺序问题。

来源:10-5 查询会议列表分页数据(后端)

董大大QAQ

2023-03-03

就是从if开始我有点不懂 为什么先添加空的对象 后给对象赋值 最后集合里面还是有值的 比如add哪里就是 首先new出来的空map 然后先添加后赋值 因为我的代码习惯是先赋值 所以一直没想明白

   String date = null;
        ArrayList resultList = new ArrayList();
        HashMap resultMap = null;
        JSONArray array = null;
        for (HashMap map : list) {
            String temp = map.get("date").toString();
            if (!temp.equals(date)) {
                date = temp;
                resultMap = new HashMap();
                resultList.add(resultMap);
                resultMap.put("date", date);
                array = new JSONArray();
                resultMap.put("list", array);
            }
            array.put(map);
        }
        return resultList;
写回答

1回答

神思者

2023-03-03

写代码习惯的事情,不影响程序运行

0
0

SpringBoot 在线协同办公小程序开发 全栈式项目实战

未来趋势型业务 + 前后端综合技术栈 + 惊艳的细节打磨

1798 学习 · 1915 问题

查看课程