public final class CollectionUtil extends Object
| Constructor and Description |
|---|
CollectionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
asList(T... args)
创建一个
List。 |
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 <T> ArrayList<T> |
createArrayList()
创建一个
ArrayList。 |
static <T> ArrayList<T> |
createArrayList(int initialCapacity)
创建一个
ArrayList。 |
static <T> ArrayList<T> |
createArrayList(Iterable<? extends T> c)
创建一个
ArrayList。 |
static <T,V extends T> |
createArrayList(V... args)
创建一个
ArrayList。 |
static <K,V> ConcurrentHashMap<K,V> |
createConcurrentHashMap()
创建一个
ConcurrentHashMap。 |
static <K,V> HashMap<K,V> |
createHashMap()
创建一个
HashMap。 |
static <K,V> HashMap<K,V> |
createHashMap(int initialCapacity)
创建一个
HashMap。 |
static <T> HashSet<T> |
createHashSet()
创建一个
HashSet。 |
static <T> HashSet<T> |
createHashSet(Iterable<? extends T> c)
创建一个
HashSet。 |
static <T,V extends T> |
createHashSet(V... args)
创建一个
HashSet。 |
static <K,V> LinkedHashMap<K,V> |
createLinkedHashMap()
创建一个
LinkedHashMap。 |
static <K,V> LinkedHashMap<K,V> |
createLinkedHashMap(int initialCapacity)
创建一个
LinkedHashMap。 |
static <T> LinkedHashSet<T> |
createLinkedHashSet()
创建一个
LinkedHashSet。 |
static <T> LinkedHashSet<T> |
createLinkedHashSet(Iterable<? extends T> c)
创建一个
LinkedHashSet。 |
static <T,V extends T> |
createLinkedHashSet(V... args)
创建一个
LinkedHashSet。 |
static <T> LinkedList<T> |
createLinkedList()
创建一个
LinkedList。 |
static <T> LinkedList<T> |
createLinkedList(Iterable<? extends T> c)
创建一个
LinkedList。 |
static <T,V extends T> |
createLinkedList(V... args)
创建一个
LinkedList。 |
static <K,V> TreeMap<K,V> |
createTreeMap()
创建一个
TreeMap。 |
static <K,V> TreeMap<K,V> |
createTreeMap(Comparator<? super K> comparator)
创建一个
TreeMap。 |
static <T> TreeSet<T> |
createTreeSet()
创建一个
TreeSet。 |
static <T> TreeSet<T> |
createTreeSet(Comparator<? super T> comparator)
创建一个
TreeSet。 |
static <T> TreeSet<T> |
createTreeSet(Comparator<? super T> comparator,
Iterable<? extends T> c)
创建一个
TreeSet。 |
static <T,V extends T> |
createTreeSet(Comparator<? super T> comparator,
V... args)
创建一个
TreeSet。 |
static <T> TreeSet<T> |
createTreeSet(Iterable<? extends T> c)
创建一个
TreeSet。 |
static <T,V extends T> |
createTreeSet(V... args)
创建一个
TreeSet。 |
static <E> Map |
extractIndexToMap(Collection<E> collection,
String keyPropertyName)
提取集合中的对象的某个属性(通过Getter函数)作为key,集合对象作为值,组合成Map.
|
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)
Return
true if the supplied Collection is null
or empty. |
static boolean |
isEmpty(Map map)
Return
true if the supplied Map is null
or empty. |
static boolean |
isNotEmpty(Collection collection)
Return
false if the supplied Collection is null
or empty. |
static <T> List<T> |
subtract(Collection<T> a,
Collection<T> b)
返回a-b的新List.
|
static String[] |
toNoNullStringArray(Collection collection) |
static <T> List<T> |
union(Collection<T> a,
Collection<T> b)
返回a+b的新List.
|
public static <T> ArrayList<T> createArrayList()
ArrayList。public static <T> ArrayList<T> createArrayList(int initialCapacity)
ArrayList。public static <T> ArrayList<T> createArrayList(Iterable<? extends T> c)
ArrayList。public static <T,V extends T> ArrayList<T> createArrayList(V... args)
ArrayList。public static <T> LinkedList<T> createLinkedList()
LinkedList。public static <T> LinkedList<T> createLinkedList(Iterable<? extends T> c)
LinkedList。public static <T,V extends T> LinkedList<T> createLinkedList(V... args)
LinkedList。public static <T> List<T> asList(T... args)
List。
和createArrayList(args)不同,本方法会返回一个不可变长度的列表,且性能高于
createArrayList(args)。
public static <K,V> HashMap<K,V> createHashMap()
HashMap。public static <K,V> HashMap<K,V> createHashMap(int initialCapacity)
HashMap。public static <K,V> LinkedHashMap<K,V> createLinkedHashMap()
LinkedHashMap。public static <K,V> LinkedHashMap<K,V> createLinkedHashMap(int initialCapacity)
LinkedHashMap。public static <K,V> TreeMap<K,V> createTreeMap()
TreeMap。public static <K,V> TreeMap<K,V> createTreeMap(Comparator<? super K> comparator)
TreeMap。public static <K,V> ConcurrentHashMap<K,V> createConcurrentHashMap()
ConcurrentHashMap。public static <T> HashSet<T> createHashSet()
HashSet。public static <T,V extends T> HashSet<T> createHashSet(V... args)
HashSet。public static <T> LinkedHashSet<T> createLinkedHashSet()
LinkedHashSet。public static <T,V extends T> LinkedHashSet<T> createLinkedHashSet(V... args)
LinkedHashSet。public static <T> LinkedHashSet<T> createLinkedHashSet(Iterable<? extends T> c)
LinkedHashSet。public static <T> TreeSet<T> createTreeSet()
TreeSet。public static <T,V extends T> TreeSet<T> createTreeSet(V... args)
TreeSet。public static <T> TreeSet<T> createTreeSet(Comparator<? super T> comparator)
TreeSet。public static <T,V extends T> TreeSet<T> createTreeSet(Comparator<? super T> comparator, V... args)
TreeSet。public static <T> TreeSet<T> createTreeSet(Comparator<? super T> comparator, Iterable<? extends T> c)
TreeSet。public static boolean isEmpty(Collection collection)
true if the supplied Collection is null
or empty. Otherwise, return false.collection - the Collection to checkpublic static boolean isNotEmpty(Collection collection)
false if the supplied Collection is null
or empty. Otherwise, return true.collection - the Collection to checkpublic static boolean isEmpty(Map map)
true if the supplied Map is null
or empty. Otherwise, return false.map - the Map to checkpublic static String[] toNoNullStringArray(Collection collection)
public static Map extractToMap(Collection collection, String keyPropertyName, String valuePropertyName) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException
collection - 来源集合.keyPropertyName - 要提取为Map中的Key值的属性名.valuePropertyName - 要提取为Map中的Value值的属性名.IllegalAccessExceptionNoSuchMethodExceptionInvocationTargetExceptionpublic static <E> Map extractIndexToMap(Collection<E> collection, String keyPropertyName)
collection - 来源集合.keyPropertyName - 要提取为Map中的Key值的属性名.public static List extractToList(Collection collection, String propertyName)
collection - 来源集合.propertyName - 要提取的属性名.IllegalAccessExceptionNoSuchMethodExceptionInvocationTargetExceptionpublic static String extractToString(Collection collection, String propertyName, String separator) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException
collection - 来源集合.propertyName - 要提取的属性名.separator - 分隔符.IllegalAccessExceptionNoSuchMethodExceptionInvocationTargetExceptionpublic static String convertToString(Collection collection, String separator)
collection - separator - public static String convertToString(Collection collection, String prefix, String postfix)
collection - prefix - postfix - public static <T> T getFirst(Collection<T> collection)
T - collection - public static <T> T getLast(Collection<T> collection)
T - collection - public static <T> List<T> union(Collection<T> a, Collection<T> b)
T - a - b - public static <T> List<T> subtract(Collection<T> a, Collection<T> b)
T - a - b - public static <T> List<T> intersection(Collection<T> a, Collection<T> b)
T - a - b - Copyright © 2006–2018 TinyGroup. All rights reserved.