Class Collections


  • public class Collections
    extends Object
    Provides static utility methods for working with collections.
    • Method Detail

      • listOf

        @SafeVarargs
        public static <E> List<E> listOf​(E... elements)
        Creates an immutable list of elements.
        Type Parameters:
        E - The element type.
        Parameters:
        elements - The list elements.
        Returns:
        An immutable list containing the provided elements.
      • mapOf

        @SafeVarargs
        public static <K,​V> Map<K,​V> mapOf​(Map.Entry<K,​V>... entries)
        Creates an immutable map of entries.
        Type Parameters:
        K - The key type.
        V - The value type.
        Parameters:
        entries - The map entries.
        Returns:
        An immutable map containing the provided entries.
      • entry

        public static <K,​V> Map.Entry<K,​V> entry​(K key,
                                                             V value)
        Creates an immutable map entry.
        Type Parameters:
        K - The key type.
        V - The value type.
        Parameters:
        key - The entry key.
        value - The entry value.
        Returns:
        An immutable map entry containing the provided key/value pair.
      • emptyListOf

        public static <E> List<E> emptyListOf​(Class<E> elementType)
        Returns an empty list.
        Type Parameters:
        E - The element type.
        Parameters:
        elementType - The element type.
        Returns:
        An empty list.
      • emptyMapOf

        public static <K,​V> Map<K,​V> emptyMapOf​(Class<K> keyType,
                                                            Class<V> valueType)
        Returns an empty map.
        Type Parameters:
        K - The key type.
        V - The value type.
        Parameters:
        keyType - The key type.
        valueType - The value type.
        Returns:
        An empty map.
      • firstIndexWhere

        public static <E> int firstIndexWhere​(List<E> list,
                                              Predicate<E> predicate)
        Returns the index of the first element in a list that matches the given predicate.
        Type Parameters:
        E - The element type.
        Parameters:
        list - The list of elements.
        predicate - The predicate.
        Returns:
        The index of the first matching element, or -1 if no match was found.
      • lastIndexWhere

        public static <E> int lastIndexWhere​(List<E> list,
                                             Predicate<E> predicate)
        Returns the index of the last element in a list that matches the given predicate.
        Type Parameters:
        E - The element type.
        Parameters:
        list - The list of elements.
        predicate - The predicate.
        Returns:
        The index of the last matching element, or -1 if no match was found.
      • valueAt

        public static Object valueAt​(Object root,
                                     Object... path)
        Returns the value at a given path.
        Parameters:
        root - The root object.
        path - The path to the value.
        Returns:
        The value at the given path, or null if the value does not exist.