|
public static List extractToList(final Collection collection, final String propertyName) {
List list = new ArrayList(collection.size());
try {
for (Object obj : collection) {
list.add(PropertyUtils.getProperty(obj, propertyName));
}
} catch (Exception e) {
throw Reflections.convertReflectionExceptionToUnchecked(e);
}
return list;
}
这段代码实现了从List 从提取每项元素的一个属性,其中使用到了Apache Common 的工具包 beanUtils =》 PropertyUtils.getProperty(obj, propertyName)
|
|