类 Collections2
- java.lang.Object
-
- net.dongliu.commons.collection.Collections2
-
public class Collections2 extends java.lang.ObjectUtil method for Collection.
-
-
构造器概要
构造器 构造器 说明 Collections2()
-
方法概要
所有方法 静态方法 具体方法 已过时的方法 修饰符和类型 方法 说明 static <S,T>
java.util.List<T>convertToList(java.util.Collection<S> c, java.util.function.Function<? super S,? extends T> mapper)Convert origin collection to new immutable List, with elements mapped by mapper.static <T> voidforEach(java.util.Collection<T> c, LastAwareConsumer<? super T> consumer)Traverse on a collection.static <T> voidforEachIndexed(java.util.Collection<T> c, IndexedConsumer<? super T> consumer)Traverse on a collection, with element index.static <T> PartitionResult<java.util.List<T>>partitionToList(java.util.Collection<T> list, java.util.function.Predicate<? super T> predicate)Divide collection to two immutable list, the first list contains elements accepted by predicate, the other contains other elements.static <T> T[]toArray(java.util.Collection<? extends T> c, java.util.function.IntFunction<T[]> maker)已过时。usingCollection.toArray(IntFunction)
-
-
-
方法详细资料
-
toArray
@Deprecated public static <T> T[] toArray(java.util.Collection<? extends T> c, java.util.function.IntFunction<T[]> maker)已过时。usingCollection.toArray(IntFunction)Convert collection to array. This method using method reference, work better than the API in Collection. Call this method as:List<String> list = Lists.of("1", "2", "3"); String[] array = Collections2.toArray(list, String[]::new);- 类型参数:
T- element type- 参数:
c- the collectionmaker- create the target array- 返回:
- the target array containing elements in collection
-
convertToList
public static <S,T> java.util.List<T> convertToList(java.util.Collection<S> c, java.util.function.Function<? super S,? extends T> mapper)Convert origin collection to new immutable List, with elements mapped by mapper.- 返回:
- list contains the result.
-
partitionToList
public static <T> PartitionResult<java.util.List<T>> partitionToList(java.util.Collection<T> list, java.util.function.Predicate<? super T> predicate)
Divide collection to two immutable list, the first list contains elements accepted by predicate, the other contains other elements.- 参数:
list- can not be null- 返回:
- two list
-
forEach
public static <T> void forEach(java.util.Collection<T> c, LastAwareConsumer<? super T> consumer)Traverse on a collection.- 类型参数:
T- the data type- 参数:
c- the collectionconsumer- the consumer
-
forEachIndexed
public static <T> void forEachIndexed(java.util.Collection<T> c, IndexedConsumer<? super T> consumer)Traverse on a collection, with element index.- 类型参数:
T- the data type- 参数:
c- the collectionconsumer- the consumer
-
-