Class CollectionUtils

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

@ReleasedSince("26.8.301") public final class CollectionUtils extends Object
Utility class providing conversion helpers for collections with mutable and unmodifiable variants.
  • Method Details

    • toSet

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

      @NotNull public static <T> @NotNull @Unmodifiable Set<T> toUnmodifiableSet(@Nullable @Nullable Collection<T> collection)
      Converts a collection into an unmodifiable Set.
      Type Parameters:
      T - the element type
      Parameters:
      collection - the source collection, can be null
      Returns:
      an unmodifiable Set, or Set.of() if the input is null or empty
    • toList

      @NotNull public static <T> @NotNull List<T> toList(@Nullable @Nullable Collection<T> collection)
      Converts a collection into a mutable List.
      Type Parameters:
      T - the element type
      Parameters:
      collection - the source collection, can be null
      Returns:
      a mutable ArrayList, or an empty list if the input is null or empty
    • toUnmodifiableList

      @NotNull public static <T> @NotNull @Unmodifiable List<T> toUnmodifiableList(@Nullable @Nullable Collection<T> collection)
      Converts a collection into an unmodifiable List.
      Type Parameters:
      T - the element type
      Parameters:
      collection - the source collection, can be null
      Returns:
      an unmodifiable List, or List.of() if the input is null or empty