public class Collections3 extends Object
| 构造器和说明 |
|---|
Collections3() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
convertToString(Collection collection,
String separator)
转换Collection所有元素(通过toString())为String, 中间以 separator分隔。
|
static String |
convertToString(Collection collection,
String prefix,
String postfix)
转换Collection所有元素(通过toString())为String, 每个元素的前面加入prefix,后面加入postfix,如mymessage。
|
static List |
extractToList(Collection collection,
String propertyName)
提取集合中的对象的一个属性(通过Getter函数), 组合成List.
|
static Map |
extractToMap(Collection collection,
String keyPropertyName,
String valuePropertyName)
提取集合中的对象的两个属性(通过Getter函数), 组合成Map.
|
static String |
extractToString(Collection collection,
String propertyName,
String separator)
提取集合中的对象的一个属性(通过Getter函数), 组合成由分割符分隔的字符串.
|
static <T> T |
getFirst(Collection<T> collection)
取得Collection的第一个元素,如果collection为空返回null.
|
static <T> T |
getLast(Collection<T> collection)
获取Collection的最后一个元素 ,如果collection为空返回null.
|
static <T> List<T> |
intersection(Collection<T> a,
Collection<T> b)
返回a与b的交集的新List.
|
static boolean |
isEmpty(Collection collection)
判断是否为空.
|
static <T> List<T> |
subtract(Collection<T> a,
Collection<T> b)
返回a-b的新List.
|
static <T> List<T> |
union(Collection<T> a,
Collection<T> b)
返回a+b的新List.
|
public static Map extractToMap(Collection collection, String keyPropertyName, String valuePropertyName)
collection - 来源集合.keyPropertyName - 要提取为Map中的Key值的属性名.valuePropertyName - 要提取为Map中的Value值的属性名.public static List extractToList(Collection collection, String propertyName)
collection - 来源集合.propertyName - 要提取的属性名.public static String extractToString(Collection collection, String propertyName, String separator)
collection - 来源集合.propertyName - 要提取的属性名.separator - 分隔符.public static String convertToString(Collection collection, String separator)
collection - separator - public static String convertToString(Collection collection, String prefix, String postfix)
collection - prefix - postfix - public static boolean isEmpty(Collection collection)
collection - public static <T> T getFirst(Collection<T> collection)
collection - public static <T> T getLast(Collection<T> collection)
collection - public static <T> List<T> union(Collection<T> a, Collection<T> b)
a - b - public static <T> List<T> subtract(Collection<T> a, Collection<T> b)
a - b - public static <T> List<T> intersection(Collection<T> a, Collection<T> b)
a - b - Copyright © 2017. All rights reserved.