Java examples for java.util:Collection Element
combine property value of elements in collection, return a String List
import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; import org.springframework.beans.BeanUtils; public class Main { /**/*from w ww . ja va 2s. c o m*/ * combine property value of elements in collection, return a String List * * @param collection * @param properties * @param delim * @return */ public static List combineProperties(Collection collection, String[] properties, String delim) { List result = new ArrayList(); for (Iterator iter = collection.iterator(); iter.hasNext();) { Object bean = iter.next(); String element = ""; for (int i = 0; i < properties.length; i++) { if (i > 0) { element += delim; } Object value = BeanUtils.getProperty(bean, properties[i]); if (value != null) { element += value; } } result.add(element); } return result; } }