网站模板的功能,网页前端技术有哪些,北苑网站建设,做网站用根据对象某一字段名#xff0c;获取字段值#xff0c;将List转换为Map中包含list#xff0c;Key为字段值#xff0c;Value为相同字段值的对象list#xff0c;快速定位具有相同字段值的对象#xff0c;转换之后便于在Map中根据字段值快速查找相同字段值的对象 //List转Map…根据对象某一字段名获取字段值将List转换为Map中包含listKey为字段值Value为相同字段值的对象list快速定位具有相同字段值的对象转换之后便于在Map中根据字段值快速查找相同字段值的对象 //List转Mappublic static K, V MapK, ListV getMapByListAndGroup(ListV list, String field) {MapK, ListV map new HashMap();if (list null) {return map;}ListV objList;for (V obj : list) {Class? clazz obj.getClass();Field f;K fieldValue null;try {f clazz.getDeclaredField(field);f.setAccessible(true);fieldValue (K) f.get(obj);} catch (Exception e) {e.printStackTrace();}if (map.containsKey(fieldValue)) {objList map.get(fieldValue);} else {objList new ArrayList();}objList.add(obj);map.put(fieldValue, objList);}return map;}