Class CollectionUtils


  • public final class CollectionUtils
    extends Object
    Utility class for Collections.
    • Method Detail

      • newArrayList

        public static <E> ArrayList<E> newArrayList​(E... elements)
        Creates a new ArrayList with the provided elements.
        Type Parameters:
        E - the elements' type
        Parameters:
        elements - the elements to add to the new ArrayList
        Returns:
        a new ArrayList with the provided elements
      • newLinkedList

        public static <E> LinkedList<E> newLinkedList​(E... elements)
        Creates a new LinkedList with the provided elements.
        Type Parameters:
        E - the elements' type
        Parameters:
        elements - the elements to add to the new LinkedList
        Returns:
        a new LinkedList with the provided elements
      • newHashSet

        public static <E> HashSet<E> newHashSet​(E... elements)
        Creates a new HashSet with the provided elements.
        Type Parameters:
        E - the elements' type
        Parameters:
        elements - the elements to add to the new HashSet
        Returns:
        a new HashSet with the provided elements
      • newLinkedHashSet

        public static <E> LinkedHashSet<E> newLinkedHashSet​(E... elements)
        Creates a new LinkedHashSet with the provided elements.
        Type Parameters:
        E - the elements' type
        Parameters:
        elements - the elements to add to the new LinkedHashSet
        Returns:
        a new LinkedHashSet with the provided elements
      • newTreeSet

        public static <E> TreeSet<E> newTreeSet​(E... elements)
        Creates a new TreeSet with the provided elements.
        Type Parameters:
        E - the elements' type
        Parameters:
        elements - the elements to add to the new TreeSet
        Returns:
        a new TreeSet with the provided elements
      • collect

        public static <C extends Collection<E>,​E> C collect​(Iterable<E> iterable,
                                                                  C outputCollection)
        Collects all the elements from the provided iterable into the provided collection.
        Type Parameters:
        C - The type of the collection
        E - The type of the iterable's elements
        Parameters:
        iterable - the iterable from which to read elements
        outputCollection - the collection where to add the iterable's elements
        Returns:
        the provided collection
      • isEmpty

        public static boolean isEmpty​(Iterable<?> iterable)
        Returns whether the provided iterable is empty, i.e. whether it has not elements.
        Parameters:
        iterable - the iterable for which to omake the determination
        Returns:
        true if the iterable is empty, false otherwise.