老师关于代码顺序问题。
来源: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
写代码习惯的事情,不影响程序运行
00
相似问题