Class LazyCollections


  • public final class LazyCollections
    extends Object
    Utility methods for lazily instantiated collections. These are useful for situations when we start off with an empty collection (where Collections.empty() * can be reused), but need to add more things.
    • Method Detail

      • lazyAdd

        public static <E> List<E> lazyAdd​(List<E> list,
                                          E obj)
        Add an element to a list, potentially transforming the list.
        Type Parameters:
        E - the type of elements in the list
        Parameters:
        list - Current list
        obj - Object that needs to be added
        Returns:
        new list
      • lazyAdd

        public static <E> Set<E> lazyAdd​(Set<E> set,
                                         E obj)
        Add an element to a set, potentially transforming the set.
        Type Parameters:
        E - the type of elements in the set
        Parameters:
        set - Current set
        obj - Object that needs to be added
        Returns:
        new set