Class ArrayUtils

java.lang.Object
com.dianxin.tori.base.utils.ArrayUtils

@ReleasedSince("26.8.301") public final class ArrayUtils extends Object
Utility class providing helper methods for standard array conversions and element checks.
  • Method Details

    • toList

      @NotNull public static <T> @NotNull List<T> toList(@Nullable T[] array)
      Converts an array into a mutable List.
      Type Parameters:
      T - the element type
      Parameters:
      array - the source array, can be null
      Returns:
      a mutable ArrayList containing the array elements, or an empty list if array is null or empty
    • toSet

      @NotNull public static <T> @NotNull Set<T> toSet(@Nullable T[] array)
      Converts an array into a mutable Set.
      Type Parameters:
      T - the element type
      Parameters:
      array - the source array, can be null
      Returns:
      a mutable HashSet containing unique array elements, or an empty set if array is null or empty
    • toArray

      @NotNull public static <T> T[] toArray(@Nullable @Nullable Collection<T> collection, @NotNull @NotNull IntFunction<T[]> generator)
      Converts a Collection into an array using the provided generator function.
      Type Parameters:
      T - the element type of the collection and the resulting array
      Parameters:
      collection - the source collection to be converted, can be null
      generator - the array constructor reference used to allocate the array of the correct type (e.g., String[]::new)
      Returns:
      an array containing all the elements in the collection, or an empty array of type T if the collection is null or empty
      Throws:
      IllegalArgumentException - if the generator is null and the collection is not null or empty
    • contains

      public static <T> boolean contains(@Nullable T[] array, @Nullable T element)
      Checks if a specific element exists within the provided array.
      Type Parameters:
      T - the element type
      Parameters:
      array - the array to inspect, can be null
      element - the element to find, can be null
      Returns:
      true if the element is found, otherwise false