Class CollectionUtils

java.lang.Object
org.apache.juneau.commons.utils.CollectionUtils

public class CollectionUtils extends Object
Utility methods for working with collections and maps.
Complex Data Structure Construction:

This class provides convenient shorthand methods for creating complex nested data structures. The primary methods for building structures are:

Examples:

// Array of lists of maps var data = a( l(m("name", "John", "age", 30)), l(m("name", "Jane", "age", 25)) ); // Compare with traditional Java syntax: List<Map<String,Object>>[] data = new List[]{ new ArrayList<>(Arrays.asList( new LinkedHashMap<>(){{ put("name", "John"); put("age", 30); }} )), new ArrayList<>(Arrays.asList( new LinkedHashMap<>(){{ put("name", "Jane"); put("age", 25); }} )) };

// Complex nested structure: Array of lists containing maps and arrays var complex = a( l( m("user", "admin", "roles", a("read", "write", "delete")), m("user", "guest", "roles", a("read")) ), l( m("status", "active", "count", 42) ) ); // Traditional Java equivalent (significantly more verbose): List<Map<String,Object>>[] complex = new List[]{ new ArrayList<>(Arrays.asList( new LinkedHashMap<>(){{ put("user", "admin"); put("roles", new String[]{"read", "write", "delete"}); }}, new LinkedHashMap<>(){{ put("user", "guest"); put("roles", new String[]{"read"}); }} )), new ArrayList<>(Arrays.asList( new LinkedHashMap<>(){{ put("status", "active"); put("count", 42); }} )) };

// Using unmodifiable maps for immutable data var config = a( m("env", "production", "debug", false), m("env", "development", "debug", true) );

Best Practices:
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T[]
    a(T... x)
    Creates an array of objects.
    static <E> E[][]
    a2(E[]... value)
    Creates a 2-dimensional array.
    static <T> List<T>
    Traverses all elements in the specified object and accumulates them into a list.
    static <E> List<E>
    addAll(List<E> value, E... entries)
    Adds all the specified values to the specified collection.
    static <E> List<E>
    addAll(List<E> value, List<E> entries)
    Adds all the specified values to the specified collection.
    static <E> Set<E>
    addAll(Set<E> value, E... entries)
    Adds all the specified values to the specified collection.
    static <E> SortedSet<E>
    addAll(SortedSet<E> value, E... entries)
    Adds all the specified values to the specified collection.
    static <T> T[]
    addAll(T[] array, T... newElements)
    Appends one or more elements to an array.
    static <T> ArrayList<T>
    al(T... values)
    Shortcut for creating an ArrayList from the specified values.
    static Object[]
    ao(Object... value)
    Creates an array of objects with the return type explicitly set to Object[].
    static <E> E[]
    array(Class<E> componentType, int length)
    Creates an array of the specified component type and length.
    static <E> E[]
    array(Collection<E> value, Class<E> componentType)
    Converts the specified collection to an array.
    static List<Object>
    Converts any array (including primitive arrays) to a List.
    static boolean[]
    booleans(boolean... value)
    Shortcut for creating a boolean array.
    static byte[]
    bytes(int... value)
    Shortcut for creating a byte array.
    static char[]
    chars(char... value)
    Shortcut for creating a char array.
    static <E> E[]
    combine(E[]... arrays)
    Combine an arbitrary number of arrays into a single array.
    static <T> boolean
    contains(T element, T[] array)
    Returns true if the specified array contains the specified element using the String.equals(Object) method.
    static List
    copyArrayToList(Object array, List list)
    Copies the specified array into the specified list.
    static <E> Collection<E>
    Creates a new collection from the specified collection.
    static <E> ArrayList<E>
    copyOf(List<E> value)
    Convenience method for copying a list.
    static <E> List<E>
    copyOf(List<E> l, Function<? super E,? extends E> valueMapper)
    Makes a deep copy of the specified list.
    static <E> List<E>
    copyOf(List<E> l, Function<? super E,? extends E> valueMapper, Supplier<List<E>> listFactory)
    Makes a deep copy of the specified list.
    static <K, V> Map<K,V>
    copyOf(Map<K,V> val)
    Creates a new map from the specified map.
    static <K, V> Map<K,V>
    copyOf(Map<K,V> m, Function<? super V,? extends V> valueMapper)
    Makes a deep copy of the specified map.
    static <K, V> Map<K,V>
    copyOf(Map<K,V> m, Function<? super V,? extends V> valueMapper, Supplier<Map<K,V>> mapFactory)
    Makes a deep copy of the specified map.
    static <E> Set<E>
    copyOf(Set<E> val)
    Creates a new set from the specified collection.
    static <E> Set<E>
    copyOf(Set<E> l, Function<? super E,? extends E> valueMapper)
    Makes a deep copy of the specified list.
    static <E> Set<E>
    copyOf(Set<E> l, Function<? super E,? extends E> valueMapper, Supplier<Set<E>> setFactory)
    Makes a deep copy of the specified list.
    static <T> T[]
    copyOf(T[] array)
    Makes a copy of the specified array.
    static double[]
    doubles(double... value)
    Shortcut for creating a double array.
    Convenience factory for a filtered, sorted, fluent map with String keys and Object values.
    static <E> E
    first(List<E> l)
    Returns the first element in a list.
    static float[]
    floats(float... value)
    Shortcut for creating a float array.
    static <E> void
    forEachReverse(E[] value, Consumer<E> action)
    Iterates the specified array in reverse order.
    static <E> void
    forEachReverse(List<E> value, Consumer<E> action)
    Iterates the specified list in reverse order.
    static <T> HashSet<T>
    hs(T... values)
    Shortcut for creating a HashSet from the specified values.
    static <T> int
    indexOf(T element, T[] array)
    Returns the index position of the element in the specified array using the String.equals(Object) method.
    static int[]
    ints(int... value)
    Shortcut for creating an int array.
    static boolean
    Returns true if the specified array is null or has a length of zero.
    static boolean
    Returns true if the specified array is not null and has a length greater than zero.
    static <T> List<T>
    l(T... values)
    Shortcut for creating an unmodifiable list out of an array of values.
    static <E> E
    last(E[] l)
    Returns the last entry in an array.
    static <E> E
    last(List<E> l)
    Returns the last entry in a list.
    static int
    length(Object array)
    Returns the length of the specified array.
    static <T> List<T>
    list(T... values)
    Shortcut for creating a modifiable list out of an array of values.
    static <E> Lists<E>
    listb(Class<E> type)
    Convenience factory for a Lists.
    static <T> List<T>
    Shortcut for creating an empty list.
    static <T> List<T>
    liste(Class<T> type)
    Shortcut for creating an empty list of the specified type.
    static <T> List<T>
    listn(Class<T> type)
    Returns a null list.
    static <E> List<E>
    listOf(Class<E> elementType, E... values)
    Convenience method for creating an ArrayList.
    static <E> ArrayList<E>
    listOfSize(int size)
    Convenience method for creating an ArrayList of the specified size.
    static <T> LinkedList<T>
    ll(T... values)
    Shortcut for creating a LinkedList from the specified values.
    static long[]
    longs(long... value)
    Shortcut for creating a long array.
    static <K, V> Map<K,V>
    m()
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
    Convenience method for creating an unmodifiable map.
    static <K, V> Map<K,V>
    m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
    Convenience method for creating an unmodifiable map.
    static <K, V> LinkedHashMap<K,V>
    map()
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
    Convenience method for creating a LinkedHashMap.
    static <K, V> LinkedHashMap<K,V>
    map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
    Convenience method for creating a LinkedHashMap.
    static <K, V> Maps<K,V>
    Convenience factory for a Maps builder.
    static <K, V> Maps<K,V>
    mapb(Class<K> keyType, Class<V> valueType)
    Convenience factory for a Maps.
    Convenience factory for a Maps with String keys and Object values.
    static <K, V> Map<K,V>
    Shortcut for creating an empty map with generic types.
    static <K, V> Map<K,V>
    mape(Class<K> keyType, Class<V> valueType)
    Shortcut for creating an empty map of the specified types.
    static <K, V> Map<K,V>
    mapn(Class<K> keyType, Class<V> valueType)
    Returns a null map.
    static <K, V> LinkedHashMap<K,V>
    mapOf(Class<K> keyType, Class<V> valueType)
    Convenience method for creating a LinkedHashMap.
    static <T> T[]
    na(Class<T> type)
    Returns null for the specified array type.
    static <E> List<E>
    prependAll(List<E> value, E... entries)
    Adds all the specified values to the specified collection.
    static <E> E[]
    reverse(E[] array)
    Reverses the elements in the specified array in-place.
    static <E> List<E>
    reverse(List<E> list)
    Returns a reversed view of the specified list.
    static <T> Stream<T>
    rstream(List<T> value)
    Returns a reverse stream of the specified list.
    static <T> LinkedHashSet<T>
    set(T... values)
    Shortcut for creating a modifiable set out of an array of values.
    static <E> Sets<E>
    setb(Class<E> type)
    Convenience factory for a Sets.
    static <T> Set<T>
    Returns an empty immutable set.
    static <E> LinkedHashSet<E>
    setOf(Class<E> elementType, E... values)
    Convenience method for creating a LinkedHashSet.
    static short[]
    shorts(int... value)
    Shortcut for creating a short array.
    static <E> List<E>
    sortedList(E... values)
    Convenience method for creating an ArrayList and sorting it.
    static <E> List<E>
    sortedList(Comparator<E> comparator, E[] values)
    Convenience method for creating an ArrayList and sorting it.
    static <E> ArrayList<E>
    sortedList(Comparator<E> comparator, Collection<E> value)
    Convenience method for creating an ArrayList and sorting it.
    static <K, V> TreeMap<K,V>
    Convenience method for creating a TreeMap.
    static <E> TreeSet<E>
    sortedSet(E... values)
    Convenience method for creating a TreeSet.
    static <T> Stream<T>
    stream(T[] array)
    Returns a stream of the specified array.
    static <E> List<E>
    synced(List<E> value)
    Wraps the specified list in Collections.unmodifiableList(List).
    static <K, V> Map<K,V>
    synced(Map<K,V> value)
    Wraps the specified map in Collections.unmodifiableMap(Map).
    static <E> Set<E>
    synced(Set<E> value)
    Wraps the specified set in Collections.unmodifiableSet(Set).
    static <E> Object
    toArray(Collection<?> c, Class<E> elementType)
    Converts the specified collection to an array.
    static final List<?>
    Converts various collection-like objects to a List.
    static <E> List<E>
    toList(Object array, Class<E> elementType)
    Converts the specified array to an ArrayList
    static <E> ArrayList<E>
    toList(Collection<E> value)
    Creates an ArrayList copy from a collection.
    static <E> ArrayList<E>
    toList(Collection<E> value, boolean nullIfEmpty)
    Creates an ArrayList copy from a collection.
    static List<Object>
    Recursively converts the specified array into a list of objects.
    static <E> Set<E>
    toSet(Collection<E> val)
    Creates a new set from the specified collection.
    static <T> Set<T>
    toSet(T[] array)
    Converts the specified array to a Set.
    static <E> TreeSet<E>
    Creates a new TreeSet from the specified collection.
    static <E> TreeSet<E>
    toSortedSet(Collection<E> value, boolean nullIfEmpty)
    Creates a new TreeSet from the specified collection.
    static <T> TreeSet<T>
    toSortedSet(Set<T> copyFrom)
    Creates a new TreeSet containing a copy of the specified set.
    static Stream<Object>
    Converts an array to a stream of objects.
    static String[]
    Converts the specified collection to an array of strings.
    static <T> void
    Traverses all elements in the specified object and executes a consumer for it.
    static <T extends Comparable<T>>
    TreeSet<T>
    ts(T... values)
    Shortcut for creating a TreeSet from the specified values.
    static <T> List<T>
    u(List<? extends T> value)
    Creates an unmodifiable view of the specified list.
    static <K, V> Map<K,V>
    u(Map<? extends K,? extends V> value)
    Creates an unmodifiable view of the specified map.
    static <T> Set<T>
    u(Set<? extends T> value)
    Creates an unmodifiable view of the specified set.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • a

      @SafeVarargs public static <T> T[] a(T... x)
      Creates an array of objects.
      Type Parameters:
      T - The component type of the array.
      Parameters:
      x - The objects to place in the array.
      Returns:
      A new array containing the specified objects.
    • a2

      @SafeVarargs public static <E> E[][] a2(E[]... value)
      Creates a 2-dimensional array.

      This method provides a convenient way to create 2D arrays with cleaner syntax than traditional Java. While you could technically use a(a(...), a(...)), that approach fails for single-row arrays like a(a(...)) because the type system collapses it into a 1D array.

      Examples:

      // 2D array with multiple rows String[][] matrix = a2( a("a", "b", "c"), a("d", "e", "f"), a("g", "h", "i") ); // Single row - this works correctly with a2() String[][] singleRow = a2(a("x", "y", "z")); // Returns String[1][3] // Without a2(), this would fail (becomes 1D array): // String[] badAttempt = a(a("x", "y", "z")); // Wrong! Returns String[3] // Empty 2D array String[][] empty = a2(); // Returns String[0][] // Compare with traditional Java syntax: String[][] traditional = new String[][] { {"a", "b", "c"}, {"d", "e", "f"}, {"g", "h", "i"} };

      Use Cases:
      • Creating matrices or grids
      • Building test data with multiple rows
      • Representing tabular data
      • Any scenario requiring a 2D array structure
      Type Parameters:
      E - The element type of the inner arrays.
      Parameters:
      value - The 1D arrays that will become rows in the 2D array.
      Returns:
      A 2D array containing the specified rows.
    • accumulate

      public static <T> List<T> accumulate(Object o)
      Traverses all elements in the specified object and accumulates them into a list.
      Type Parameters:
      T - The element type.
      Parameters:
      o - The object to traverse.
      Returns:
      A list containing all accumulated elements.
    • addAll

      @SafeVarargs public static <E> List<E> addAll(List<E> value, E... entries)
      Adds all the specified values to the specified collection. Creates a new set if the value is null.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to add to.
      entries - The entries to add.
      Returns:
      The set.
    • addAll

      public static <E> List<E> addAll(List<E> value, List<E> entries)
      Adds all the specified values to the specified collection. Creates a new set if the value is null.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to add to.
      entries - The entries to add.
      Returns:
      The set.
    • addAll

      @SafeVarargs public static <E> Set<E> addAll(Set<E> value, E... entries)
      Adds all the specified values to the specified collection. Creates a new set if the value is null.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to add to.
      entries - The entries to add.
      Returns:
      The set.
    • addAll

      @SafeVarargs public static <E> SortedSet<E> addAll(SortedSet<E> value, E... entries)
      Adds all the specified values to the specified collection. Creates a new set if the value is null.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to add to.
      entries - The entries to add.
      Returns:
      The set.
    • addAll

      public static <T> T[] addAll(T[] array, T... newElements)
      Appends one or more elements to an array.
      Type Parameters:
      T - The element type.
      Parameters:
      array - The array to append to.
      newElements - The new elements to append to the array.
      Returns:
      A new array with the specified elements appended.
    • ao

      public static Object[] ao(Object... value)
      Creates an array of objects with the return type explicitly set to Object[].

      This method is useful when you need to force the return type to be Object[] regardless of the actual types of the elements passed in. This is particularly helpful in scenarios where:

      • You're mixing different types in the same array
      • You need to avoid type inference issues with the generic a() method
      • You're working with APIs that specifically require Object[]
      • You want to ensure maximum flexibility in what can be stored in the array
      Examples:

      // Mixed types - works perfectly with ao() Object[] mixed = ao("string", 42, true, 3.14, null); // Force Object[] return type even for uniform types Object[] strings = ao("a", "b", "c"); // Returns Object[], not String[] // Compare with a() which infers the most specific type: String[] typed = a("a", "b", "c"); // Returns String[] // Useful when you need Object[] for APIs: void someMethod(Object[] args) { ... } someMethod(ao("test", 123, true)); // No type issues // Empty Object array Object[] empty = ao(); // With null values Object[] withNulls = ao("value", null, 42, null);

      When to Use:
      • Use a() when you want type inference for homogeneous arrays
      • Use ao() when you explicitly need Object[] or have mixed types
      Parameters:
      value - The objects to place in the array.
      Returns:
      A new Object[] containing the specified objects.
    • array

      public static <E> E[] array(Class<E> componentType, int length)
      Creates an array of the specified component type and length.
      Type Parameters:
      E - The component type of the array.
      Parameters:
      componentType - The component type of the array.
      length - The length of the array.
      Returns:
      A new array of the specified type and length. Never null.
    • array

      public static <E> E[] array(Collection<E> value, Class<E> componentType)
      Converts the specified collection to an array.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to convert.
      componentType - The component type of the array.
      Returns:
      A new array.
    • arrayToList

      public static List<Object> arrayToList(Object array)
      Converts any array (including primitive arrays) to a List.
      Parameters:
      array - The array to convert. Can be any array type including primitives.
      Returns:
      A List containing the array elements. Primitive values are auto-boxed. Returns null if the input is null.
      Throws:
      IllegalArgumentException - if the input is not an array.
    • booleans

      public static boolean[] booleans(boolean... value)
      Shortcut for creating a boolean array.
      Example:

      boolean[] myArray = booleans(true, false, true);

      Parameters:
      value - The values to initialize the array with.
      Returns:
      A new boolean array.
    • bytes

      public static byte[] bytes(int... value)
      Shortcut for creating a byte array.

      Accepts int values and converts them to bytes, eliminating the need for explicit byte casts.

      Example:

      byte[] myArray = bytes(1, 2, 3);

      Parameters:
      value - The int values to convert to bytes. Values outside the byte range (-128 to 127) will be truncated.
      Returns:
      A new byte array.
    • chars

      public static char[] chars(char... value)
      Shortcut for creating a char array.
      Example:

      char[] myArray = chars('a', 'b', 'c');

      Parameters:
      value - The values to initialize the array with.
      Returns:
      A new char array.
    • combine

      public static <E> E[] combine(E[]... arrays)
      Combine an arbitrary number of arrays into a single array.
      Type Parameters:
      E - The element type.
      Parameters:
      arrays - Collection of arrays to combine.
      Returns:
      A new combined array, or null if all arrays are null.
    • contains

      public static <T> boolean contains(T element, T[] array)
      Returns true if the specified array contains the specified element using the String.equals(Object) method.
      Parameters:
      element - The element to check for.
      array - The array to check.
      Returns:
      true if the specified array contains the specified element, false if the array or element is null.
    • copyArrayToList

      public static List copyArrayToList(Object array, List list)
      Copies the specified array into the specified list.

      Works on both object and primitive arrays.

      Parameters:
      array - The array to copy into a list.
      list - The list to copy the values into.
      Returns:
      The same list passed in.
    • copyOf

      public static <E> Collection<E> copyOf(Collection<E> val)
      Creates a new collection from the specified collection.
      Type Parameters:
      E - The element type.
      Parameters:
      val - The value to copy from.
      Returns:
      A new LinkedHashSet, or null if the input was null.
    • copyOf

      public static <E> ArrayList<E> copyOf(List<E> value)
      Convenience method for copying a list.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The list to copy.
      Returns:
      A new modifiable list.
    • copyOf

      public static <E> List<E> copyOf(List<E> l, Function<? super E,? extends E> valueMapper)
      Makes a deep copy of the specified list.
      Type Parameters:
      E - The entry type.
      Parameters:
      l - The list to copy.
      valueMapper - The function to apply to each value in the list.
      Returns:
      A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
    • copyOf

      public static <E> List<E> copyOf(List<E> l, Function<? super E,? extends E> valueMapper, Supplier<List<E>> listFactory)
      Makes a deep copy of the specified list.
      Type Parameters:
      E - The entry type.
      Parameters:
      l - The list to copy.
      valueMapper - The function to apply to each value in the list.
      listFactory - The factory for creating the list.
      Returns:
      A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
    • copyOf

      public static <K, V> Map<K,V> copyOf(Map<K,V> val)
      Creates a new map from the specified map.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      val - The value to copy from.
      Returns:
      A new LinkedHashMap, or null if the input was null.
    • copyOf

      public static <K, V> Map<K,V> copyOf(Map<K,V> m, Function<? super V,? extends V> valueMapper)
      Makes a deep copy of the specified map.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      m - The map to copy.
      valueMapper - The function to apply to each value in the map.
      Returns:
      A new map with the same keys as the specified map, but with values transformed by the specified function. Null if the map being copied was null.
    • copyOf

      public static <K, V> Map<K,V> copyOf(Map<K,V> m, Function<? super V,? extends V> valueMapper, Supplier<Map<K,V>> mapFactory)
      Makes a deep copy of the specified map.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      m - The map to copy.
      valueMapper - The function to apply to each value in the map.
      mapFactory - The factory for creating the map.
      Returns:
      A new map with the same keys as the specified map, but with values transformed by the specified function. Null if the map being copied was null.
    • copyOf

      public static <E> Set<E> copyOf(Set<E> val)
      Creates a new set from the specified collection.
      Type Parameters:
      E - The element type.
      Parameters:
      val - The value to copy from.
      Returns:
      A new LinkedHashSet, or null if the input was null.
    • copyOf

      public static <E> Set<E> copyOf(Set<E> l, Function<? super E,? extends E> valueMapper)
      Makes a deep copy of the specified list.
      Type Parameters:
      E - The entry type.
      Parameters:
      l - The list to copy.
      valueMapper - The function to apply to each value in the list.
      Returns:
      A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
    • copyOf

      public static <E> Set<E> copyOf(Set<E> l, Function<? super E,? extends E> valueMapper, Supplier<Set<E>> setFactory)
      Makes a deep copy of the specified list.
      Type Parameters:
      E - The entry type.
      Parameters:
      l - The list to copy.
      valueMapper - The function to apply to each value in the list.
      setFactory - The factory for creating sets.
      Returns:
      A new list with the same values as the specified list, but with values transformed by the specified function. Null if the list being copied was null.
    • copyOf

      public static <T> T[] copyOf(T[] array)
      Makes a copy of the specified array.
      Type Parameters:
      T - The element type.
      Parameters:
      array - The array to copy.
      Returns:
      A new copy of the array, or null if the array was null.s
    • doubles

      public static double[] doubles(double... value)
      Shortcut for creating a double array.
      Example:

      double[] myArray = doubles(1.0, 2.0, 3.0);

      Parameters:
      value - The values to initialize the array with.
      Returns:
      A new double array.
    • first

      public static <E> E first(List<E> l)
      Returns the first element in a list.
      Type Parameters:
      E - The element type.
      Parameters:
      l - The list. Can be null.
      Returns:
      The first element in the list, or null if the list is null or empty.
    • floats

      public static float[] floats(float... value)
      Shortcut for creating a float array.
      Example:

      float[] myArray = floats(1.0f, 2.0f, 3.0f);

      Parameters:
      value - The values to initialize the array with.
      Returns:
      A new float array.
    • forEachReverse

      public static <E> void forEachReverse(E[] value, Consumer<E> action)
      Iterates the specified array in reverse order.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The array to iterate.
      action - The action to perform.
    • forEachReverse

      public static <E> void forEachReverse(List<E> value, Consumer<E> action)
      Iterates the specified list in reverse order.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The list to iterate.
      action - The action to perform.
    • indexOf

      public static <T> int indexOf(T element, T[] array)
      Returns the index position of the element in the specified array using the String.equals(Object) method.
      Parameters:
      element - The element to check for.
      array - The array to check.
      Returns:
      The index position of the element in the specified array, or -1 if the array doesn't contain the element, or the array or element is null.
    • ints

      public static int[] ints(int... value)
      Shortcut for creating an int array.
      Example:

      int[] myArray = ints(1, 2, 3);

      Parameters:
      value - The values to initialize the array with.
      Returns:
      A new int array.
    • isEmptyArray

      public static boolean isEmptyArray(Object[] array)
      Returns true if the specified array is null or has a length of zero.
      Parameters:
      array - The array to check.
      Returns:
      true if the specified array is null or has a length of zero.
    • isNotEmptyArray

      public static boolean isNotEmptyArray(Object[] array)
      Returns true if the specified array is not null and has a length greater than zero.
      Parameters:
      array - The array to check.
      Returns:
      true if the specified array is not null and has a length greater than zero.
    • l

      @SafeVarargs public static <T> List<T> l(T... values)
      Shortcut for creating an unmodifiable list out of an array of values.
      Type Parameters:
      T - The element type.
      Parameters:
      values - The values to add to the list.
      Returns:
      An unmodifiable list containing the specified values, or null if the input is null.
    • last

      public static <E> E last(E[] l)
      Returns the last entry in an array.
      Type Parameters:
      E - The element type.
      Parameters:
      l - The array.
      Returns:
      The last element, or null if the array is null or empty.
    • last

      public static <E> E last(List<E> l)
      Returns the last entry in a list.
      Type Parameters:
      E - The element type.
      Parameters:
      l - The list.
      Returns:
      The last element, or null if the list is null or empty.
    • length

      public static int length(Object array)
      Returns the length of the specified array.

      This is a null-safe convenience method that wraps Array.getLength(Object). Works with both object arrays and primitive arrays.

      Example:

      String[] array1 = {"foo", "bar"}; int[] array2 = {1, 2, 3}; int len1 = length(array1); // Returns 2 int len2 = length(array2); // Returns 3 int len3 = length(null); // Returns 0

      Parameters:
      array - The array object. Can be null.
      Returns:
      The length of the array, or 0 if the array is null or not an array.
    • list

      @SafeVarargs public static <T> List<T> list(T... values)
      Shortcut for creating a modifiable list out of an array of values.
      Type Parameters:
      T - The element type.
      Parameters:
      values - The values to add to the list.
      Returns:
      A modifiable list containing the specified values.
    • al

      @SafeVarargs public static <T> ArrayList<T> al(T... values)
      Shortcut for creating an ArrayList from the specified values.

      This is a convenience method that creates a modifiable ArrayList.

      Example:

      List<String> list = al("a", "b", "c");

      Type Parameters:
      T - The element type.
      Parameters:
      values - The values to add to the list.
      Returns:
      A new modifiable ArrayList containing the specified values.
      See Also:
    • ll

      @SafeVarargs public static <T> LinkedList<T> ll(T... values)
      Shortcut for creating a LinkedList from the specified values.

      This is a convenience method that creates a modifiable LinkedList.

      Example:

      List<String> list = ll("a", "b", "c");

      Type Parameters:
      T - The element type.
      Parameters:
      values - The values to add to the list.
      Returns:
      A new modifiable LinkedList containing the specified values.
    • hs

      @SafeVarargs public static <T> HashSet<T> hs(T... values)
      Shortcut for creating a HashSet from the specified values.

      This is a convenience method that creates a modifiable HashSet.

      Example:

      Set<String> set = hs("a", "b", "c");

      Type Parameters:
      T - The element type.
      Parameters:
      values - The values to add to the set.
      Returns:
      A new modifiable HashSet containing the specified values.
    • ts

      @SafeVarargs public static <T extends Comparable<T>> TreeSet<T> ts(T... values)
      Shortcut for creating a TreeSet from the specified values.

      This is a convenience method that creates a modifiable TreeSet. Values must be comparable.

      Example:

      Set<String> set = ts("c", "a", "b"); // Sorted: a, b, c

      Type Parameters:
      T - The element type (must be Comparable).
      Parameters:
      values - The values to add to the set.
      Returns:
      A new modifiable TreeSet containing the specified values.
    • listb

      public static <E> Lists<E> listb(Class<E> type)
      Convenience factory for a Lists.
      Type Parameters:
      E - The element type.
      Parameters:
      type - The element type.
      Returns:
      A new list builder.
    • liste

      public static <T> List<T> liste()
      Shortcut for creating an empty list.

      This is a convenience method that provides a more concise syntax than Collections.emptyList(). The "e" suffix indicates "empty".

      Example:

      List<String> myList = liste();

      Type Parameters:
      T - The element type.
      Returns:
      An empty unmodifiable list.
    • liste

      public static <T> List<T> liste(Class<T> type)
      Shortcut for creating an empty list of the specified type.
      Type Parameters:
      T - The element type.
      Parameters:
      type - The element type class.
      Returns:
      An empty list.
    • listn

      public static <T> List<T> listn(Class<T> type)
      Returns a null list.
      Type Parameters:
      T - The element type.
      Parameters:
      type - The element type class.
      Returns:
      null.
    • listOf

      @SafeVarargs public static <E> List<E> listOf(Class<E> elementType, E... values)
      Convenience method for creating an ArrayList.
      Type Parameters:
      E - The element type.
      Parameters:
      elementType - The element type.
      values - The values to initialize the list with.
      Returns:
      A new modifiable list.
    • listOfSize

      public static <E> ArrayList<E> listOfSize(int size)
      Convenience method for creating an ArrayList of the specified size.
      Type Parameters:
      E - The element type.
      Parameters:
      size - The initial size of the list.
      Returns:
      A new modifiable list.
    • longs

      public static long[] longs(long... value)
      Shortcut for creating a long array.
      Example:

      long[] myArray = longs(1L, 2L, 3L);

      Parameters:
      value - The values to initialize the array with.
      Returns:
      A new long array.
    • m

      public static <K, V> Map<K,V> m()
      Convenience method for creating an unmodifiable map.
      Type Parameters:
      K - The key type.
      V - The value type.
      Returns:
      A new unmodifiable empty map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      k8 - Key 8.
      v8 - Value 8.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      k8 - Key 8.
      v8 - Value 8.
      k9 - Key 9.
      v9 - Value 9.
      Returns:
      A new unmodifiable map.
    • m

      public static <K, V> Map<K,V> m(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
      Convenience method for creating an unmodifiable map. Unlike Map.of(...), supports null keys/values and preserves insertion order.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      k8 - Key 8.
      v8 - Value 8.
      k9 - Key 9.
      v9 - Value 9.
      k10 - Key 10.
      v10 - Value 10.
      Returns:
      A new unmodifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map()
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      k8 - Key 8.
      v8 - Value 8.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      k8 - Key 8.
      v8 - Value 8.
      k9 - Key 9.
      v9 - Value 9.
      Returns:
      A new modifiable map.
    • map

      public static <K, V> LinkedHashMap<K,V> map(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7, K k8, V v8, K k9, V v9, K k10, V v10)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      k1 - Key 1.
      v1 - Value 1.
      k2 - Key 2.
      v2 - Value 2.
      k3 - Key 3.
      v3 - Value 3.
      k4 - Key 4.
      v4 - Value 4.
      k5 - Key 5.
      v5 - Value 5.
      k6 - Key 6.
      v6 - Value 6.
      k7 - Key 7.
      v7 - Value 7.
      k8 - Key 8.
      v8 - Value 8.
      k9 - Key 9.
      v9 - Value 9.
      k10 - Key 10.
      v10 - Value 10.
      Returns:
      A new modifiable map.
    • mapb

      public static <K, V> Maps<K,V> mapb()
      Convenience factory for a Maps builder.

      This is a shortcut for Maps.create().ordered().

      Example:

      Map<String,Object> map = mapb() .add("foo", 1) .add("bar", 2) .build();

      Type Parameters:
      K - The key type.
      V - The value type.
      Returns:
      A new map builder.
      See Also:
    • mapb_so

      public static Maps<String,Object> mapb_so()
      Convenience factory for a Maps with String keys and Object values.

      This is a shortcut for Maps.create(String.class, Object.class).

      Example:

      Map<String,Object> map = mapb() .add("foo", 1) .add("bar", 2) .build();

      This builder supports optional filtering to automatically exclude unwanted values:

      // Build a map excluding null and empty values Map<String,Object> map = mapb().filtered() .add("foo", null) // Excluded .add("bar", "") // Excluded .add("baz", "value") // Included .build();

      Returns:
      A new map builder.
      See Also:
    • filteredBeanPropertyMap

      Convenience factory for a filtered, sorted, fluent map with String keys and Object values.

      This is a shortcut for Maps.create(String.class, Object.class).filtered().sorted().buildFluent().

      This is typically used for creating property maps in toString() methods that need to be sorted and filtered.

      Example:

      // In a properties() method return filteredBeanPropertyMap() .a("name", name) .a("value", value);

      Returns:
      A new filtered, sorted, fluent map builder.
      See Also:
    • mapb

      public static <K, V> Maps<K,V> mapb(Class<K> keyType, Class<V> valueType)
      Convenience factory for a Maps.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      keyType - The key type.
      valueType - The value type.
      Returns:
      A new map builder.
    • mape

      public static <K, V> Map<K,V> mape(Class<K> keyType, Class<V> valueType)
      Shortcut for creating an empty map of the specified types.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      keyType - The key type class.
      valueType - The value type class.
      Returns:
      An empty unmodifiable map.
    • mape

      public static <K, V> Map<K,V> mape()
      Shortcut for creating an empty map with generic types.

      This is a convenience method that creates an empty unmodifiable map without requiring explicit type parameters. The types will be inferred from usage context.

      Type Parameters:
      K - The key type.
      V - The value type.
      Returns:
      An empty unmodifiable map.
    • mapn

      public static <K, V> Map<K,V> mapn(Class<K> keyType, Class<V> valueType)
      Returns a null map.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      keyType - The key type class.
      valueType - The value type class.
      Returns:
      null.
    • mapOf

      public static <K, V> LinkedHashMap<K,V> mapOf(Class<K> keyType, Class<V> valueType)
      Convenience method for creating a LinkedHashMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      keyType - The key type.
      valueType - The value type.
      Returns:
      A new modifiable map.
    • na

      public static <T> T[] na(Class<T> type)
      Returns null for the specified array type.
      Type Parameters:
      T - The component type.
      Parameters:
      type - The component type class.
      Returns:
      null.
    • prependAll

      @SafeVarargs public static <E> List<E> prependAll(List<E> value, E... entries)
      Adds all the specified values to the specified collection. Creates a new set if the value is null.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to add to.
      entries - The entries to add.
      Returns:
      The set.
    • reverse

      public static <E> E[] reverse(E[] array)
      Reverses the elements in the specified array in-place.
      Type Parameters:
      E - The element type.
      Parameters:
      array - The array to reverse.
      Returns:
      The same array, reversed.
    • reverse

      public static <E> List<E> reverse(List<E> list)
      Returns a reversed view of the specified list.

      The returned list is a live view that reflects changes to the original list.

      Type Parameters:
      E - The element type.
      Parameters:
      list - The list to reverse.
      Returns:
      A reversed view of the list.
    • rstream

      public static <T> Stream<T> rstream(List<T> value)
      Returns a reverse stream of the specified list.
      Example:

      List<String> list = list("a", "b", "c"); Stream<String> reversed = rstream(list); // Produces stream: "c", "b", "a"

      Type Parameters:
      T - The element type.
      Parameters:
      value - The list to stream in reverse order. Can be null.
      Returns:
      A stream of the list elements in reverse order, or an empty stream if the list is null or empty.
    • set

      @SafeVarargs public static <T> LinkedHashSet<T> set(T... values)
      Shortcut for creating a modifiable set out of an array of values.
      Type Parameters:
      T - The element type.
      Parameters:
      values - The values to add to the set.
      Returns:
      A modifiable LinkedHashSet containing the specified values.
    • sete

      public static <T> Set<T> sete()
      Returns an empty immutable set.

      This is a convenience method that returns Collections.emptySet().

      Example:

      Set<String> empty = CollectionUtils.sete(); // Returns Collections.emptySet()

      Type Parameters:
      T - The element type.
      Returns:
      An empty immutable set.
      See Also:
    • setb

      public static <E> Sets<E> setb(Class<E> type)
      Convenience factory for a Sets.
      Type Parameters:
      E - The element type.
      Parameters:
      type - The element type.
      Returns:
      A new set builder.
    • setOf

      @SafeVarargs public static <E> LinkedHashSet<E> setOf(Class<E> elementType, E... values)
      Convenience method for creating a LinkedHashSet.
      Type Parameters:
      E - The element type.
      Parameters:
      elementType - The element type.
      values - The values to initialize the set with.
      Returns:
      A new modifiable set.
    • shorts

      public static short[] shorts(int... value)
      Shortcut for creating a short array.

      Accepts int values and converts them to shorts, eliminating the need for explicit short casts.

      Example:

      short[] myArray = shorts(1, 2, 3);

      Parameters:
      value - The int values to convert to shorts. Values outside the short range (-32768 to 32767) will be truncated.
      Returns:
      A new short array.
    • sortedList

      public static <E> ArrayList<E> sortedList(Comparator<E> comparator, Collection<E> value)
      Convenience method for creating an ArrayList and sorting it.
      Type Parameters:
      E - The element type.
      Parameters:
      comparator - The comparator to use to sort the list.
      value - The values to initialize the list with.
      Returns:
      A new modifiable list.
    • sortedList

      public static <E> List<E> sortedList(Comparator<E> comparator, E[] values)
      Convenience method for creating an ArrayList and sorting it.
      Type Parameters:
      E - The element type.
      Parameters:
      comparator - The comparator to use to sort the list.
      values - The values to initialize the list with.
      Returns:
      A new modifiable list.
    • sortedList

      @SafeVarargs public static <E> List<E> sortedList(E... values)
      Convenience method for creating an ArrayList and sorting it.
      Type Parameters:
      E - The element type.
      Parameters:
      values - The values to initialize the list with.
      Returns:
      A new modifiable list.
    • sortedMap

      public static <K, V> TreeMap<K,V> sortedMap()
      Convenience method for creating a TreeMap.
      Type Parameters:
      K - The key type.
      V - The value type.
      Returns:
      A new modifiable set.
    • sortedSet

      @SafeVarargs public static <E> TreeSet<E> sortedSet(E... values)
      Convenience method for creating a TreeSet.

      Note: null values in the varargs array are automatically filtered out because TreeSet does not support null elements.

      Type Parameters:
      E - The element type.
      Parameters:
      values - The values to initialize the set with.
      Can contain null values (they will be filtered out).
      Returns:
      A new modifiable set.
    • stream

      public static <T> Stream<T> stream(T[] array)
      Returns a stream of the specified array.

      Gracefully handles null arrays by returning an empty stream.

      Example:

      String[] array = {"a", "b", "c"}; // Prints "a", "b", "c" stream(array).forEach(System.out::println); // Handles null gracefully - returns empty stream stream(null).forEach(System.out::println); // Prints nothing

      Type Parameters:
      T - The element type.
      Parameters:
      array - The array to stream. Can be null.
      Returns:
      A stream of the array elements, or an empty stream if the array is null.
    • synced

      public static <E> List<E> synced(List<E> value)
      Wraps the specified list in Collections.unmodifiableList(List).
      Type Parameters:
      E - The element type.
      Parameters:
      value - The list to wrap.
      Returns:
      The wrapped list.
    • synced

      public static <K, V> Map<K,V> synced(Map<K,V> value)
      Wraps the specified map in Collections.unmodifiableMap(Map).
      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      value - The map to wrap.
      Returns:
      The wrapped map.
    • synced

      public static <E> Set<E> synced(Set<E> value)
      Wraps the specified set in Collections.unmodifiableSet(Set).
      Type Parameters:
      E - The element type.
      Parameters:
      value - The set to wrap.
      Returns:
      The wrapped set.
    • toArray

      public static <E> Object toArray(Collection<?> c, Class<E> elementType)
      Converts the specified collection to an array.

      Works on both object and primitive arrays.

      Type Parameters:
      E - The element type.
      Parameters:
      c - The collection to convert to an array.
      elementType - The component type of the collection.
      Returns:
      A new array.
    • toList

      public static <E> ArrayList<E> toList(Collection<E> value)
      Creates an ArrayList copy from a collection.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to copy from.
      Returns:
      A new modifiable list.
    • toList

      public static <E> ArrayList<E> toList(Collection<E> value, boolean nullIfEmpty)
      Creates an ArrayList copy from a collection.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The collection to copy from.
      nullIfEmpty - If true will return null if the collection is empty.
      Returns:
      A new modifiable list.
    • toList

      public static final List<?> toList(Object o)
      Converts various collection-like objects to a List.

      This utility method enables testing of any collection-like object by converting it to a List that can be passed to methods such as TestUtils.assertList().

      Supported Input Types:
      • List: Returns the input unchanged
      • Iterable: Any collection, set, queue, etc. (converted to List preserving order)
      • Iterator: Converts iterator contents to List
      • Enumeration: Converts enumeration contents to List
      • Stream: Converts stream contents to List (stream is consumed)
      • Map: Converts map entries to List of Map.Entry objects
      • Array: Converts any array type (including primitive arrays) to List
      Usage Examples:

      // Test a Set Set<String> mySet = Set.of("a", "b", "c"); assertList(toList(mySet), "a", "b", "c"); // Test an array String[] myArray = {"x", "y", "z"}; assertList(toList(myArray), "x", "y", "z"); // Test a primitive array int[] numbers = {1, 2, 3}; assertList(toList(numbers), "1", "2", "3"); // Test a Stream Stream<String> myStream = Stream.of("foo", "bar"); assertList(toList(myStream), "foo", "bar"); // Test a Map (converted to entries) Map<String,Integer> myMap = Map.of("a", 1, "b", 2); assertList(toList(myMap), "a=1", "b=2"); // Test any Iterable collection Queue<String> myQueue = new LinkedList<>(List.of("first", "second")); assertList(toList(myQueue), "first", "second");

      Integration with Testing:

      This method is specifically designed to work with testing frameworks to provide a unified testing approach for all collection-like types. Instead of having separate assertion methods for arrays, sets, and other collections, you can convert them all to Lists and use standard list assertion methods.

      Parameters:
      o - The object to convert to a List. Must not be null and must be a supported collection-like type.
      Returns:
      A List containing the elements from the input object.
      Throws:
      IllegalArgumentException - if the input object cannot be converted to a List.
      See Also:
    • toList

      public static <E> List<E> toList(Object array, Class<E> elementType)
      Converts the specified array to an ArrayList
      Type Parameters:
      E - The element type.
      Parameters:
      array - The array to convert.
      elementType - The type of objects in the array. It must match the actual component type in the array.
      Returns:
      A new ArrayList
    • toObjectList

      public static List<Object> toObjectList(Object array)
      Recursively converts the specified array into a list of objects.
      Parameters:
      array - The array to convert.
      Returns:
      A new ArrayList
    • toSet

      public static <E> Set<E> toSet(Collection<E> val)
      Creates a new set from the specified collection.
      Type Parameters:
      E - The element type.
      Parameters:
      val - The value to copy from.
      Returns:
      A new LinkedHashSet, or null if the input was null.
    • toSet

      public static <T> Set<T> toSet(T[] array)
      Converts the specified array to a Set.

      The order of the entries in the set are the same as the array.

      Type Parameters:
      T - The entry type of the array.
      Parameters:
      array - The array being wrapped in a Set interface.
      Returns:
      The new set.
    • toSortedSet

      public static <E> TreeSet<E> toSortedSet(Collection<E> value)
      Creates a new TreeSet from the specified collection.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The value to copy from.
      Returns:
      A new TreeSet, or null if the input was null.
    • toSortedSet

      public static <E> TreeSet<E> toSortedSet(Collection<E> value, boolean nullIfEmpty)
      Creates a new TreeSet from the specified collection.
      Type Parameters:
      E - The element type.
      Parameters:
      value - The value to copy from.
      nullIfEmpty - If true returns null if the collection is empty.
      Returns:
      A new TreeSet, or null if the input was null.
    • toSortedSet

      public static <T> TreeSet<T> toSortedSet(Set<T> copyFrom)
      Creates a new TreeSet containing a copy of the specified set.
      Type Parameters:
      T - The element type.
      Parameters:
      copyFrom - The set to copy from.
      Returns:
      A new TreeSet, or null if the set was null.
    • toStream

      public static Stream<Object> toStream(Object array)
      Converts an array to a stream of objects.
      Parameters:
      array - The array to convert.
      Returns:
      A new stream.
    • toStringArray

      public static String[] toStringArray(Collection<?> c)
      Converts the specified collection to an array of strings.

      Entries are converted to strings using Object.toString(). null values remain null.

      Parameters:
      c - The collection to convert.
      Returns:
      The collection as a string array.
    • traverse

      public static <T> void traverse(Object o, Consumer<T> c)
      Traverses all elements in the specified object and executes a consumer for it.
      Type Parameters:
      T - The element type.
      Parameters:
      o - The object to traverse.
      c - The consumer of the objects.
    • u

      public static <T> List<T> u(List<? extends T> value)
      Creates an unmodifiable view of the specified list.

      This is a null-safe wrapper around Collections.unmodifiableList(List).

      Type Parameters:
      T - The element type.
      Parameters:
      value - The list to make unmodifiable. Can be null.
      Returns:
      An unmodifiable view of the list, or null if the input was null.
    • u

      public static <K, V> Map<K,V> u(Map<? extends K,? extends V> value)
      Creates an unmodifiable view of the specified map.

      This is a null-safe wrapper around Collections.unmodifiableMap(Map).

      Type Parameters:
      K - The key type.
      V - The value type.
      Parameters:
      value - The map to make unmodifiable. Can be null.
      Returns:
      An unmodifiable view of the map, or null if the input was null.
    • u

      public static <T> Set<T> u(Set<? extends T> value)
      Creates an unmodifiable view of the specified set.

      This is a null-safe wrapper around Collections.unmodifiableSet(Set).

      Type Parameters:
      T - The element type.
      Parameters:
      value - The set to make unmodifiable. Can be null.
      Returns:
      An unmodifiable view of the set, or null if the input was null.