利用数组与for循环减少代码冗余:
//如果不为空则把内容加入map中,如果不使用for循环则一共需写6个if判断语句。
Map nodeDetail = new HashMap();
String[] mapContent ={"processStatus","processTime","processTime","logType","auditType",
"channelId","channelName","sourceProvider"};
for (int i=0;i<6;i++){
if(j.getString(mapContent[i])!=null){
nodeDetail.put(mapContent[i],j.getString(mapContent[i]));
}
}