public static <K, E> Map<K, E> convert2(Collection<E> col, String propertyName)
{
Map<K, E> map = new HashMap<K, E>();
if(null == col){
return map;
}
for (E obj : col) {
BeanMap bm = new BeanMap(obj);
K value = (K)bm.get(propertyName);
map.put(value, obj);
}
return map;
}
调用
List<DsmallCategory> normalList = null;
Map<Integer, DsmallCategory> normal = Util.<Integer, DsmallCategory> convert2(normalList, "cateId");
{
Map<K, E> map = new HashMap<K, E>();
if(null == col){
return map;
}
for (E obj : col) {
BeanMap bm = new BeanMap(obj);
K value = (K)bm.get(propertyName);
map.put(value, obj);
}
return map;
}
调用
List<DsmallCategory> normalList = null;
Map<Integer, DsmallCategory> normal = Util.<Integer, DsmallCategory> convert2(normalList, "cateId");