类 Collections2


  • public class Collections2
    extends java.lang.Object
    Util method for Collection.
    • 方法概要

      所有方法 静态方法 具体方法 已过时的方法 
      修饰符和类型 方法 说明
      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> void forEach​(java.util.Collection<T> c, LastAwareConsumer<? super T> consumer)
      Traverse on a collection.
      static <T> void forEachIndexed​(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)
      已过时。
      using Collection.toArray(IntFunction)
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • Collections2

        public Collections2()
    • 方法详细资料

      • toArray

        @Deprecated
        public static <T> T[] toArray​(java.util.Collection<? extends T> c,
                                      java.util.function.IntFunction<T[]> maker)
        已过时。
        using Collection.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 collection
        maker - 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 collection
        consumer - 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 collection
        consumer - the consumer