Class Lists

  • All Implemented Interfaces:
    Utils

    public abstract class Lists
    extends java.lang.Object
    implements Utils
    The utility class for List for Modern JDK(9+), which supports the feedback if Java Runtime is below JDK 9.
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    ListUtils, List
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <E> java.util.List<E> ofList()
      Returns an empty unmodifiable list.
      static <E> java.util.List<E> ofList​(E e1)
      Returns an unmodifiable list containing one element.
      static <E> java.util.List<E> ofList​(E... elements)
      Returns an unmodifiable list containing the specified elements.
      static <E> java.util.List<E> ofList​(E e1, E e2)
      Returns an unmodifiable list containing two elements.
      static <E> java.util.List<E> ofList​(E e1, E e2, E e3)
      Returns an unmodifiable list containing three elements.
      static <E> java.util.List<E> ofList​(E e1, E e2, E e3, E e4)
      Returns an unmodifiable list containing four elements.
      static <E> java.util.List<E> ofList​(E e1, E e2, E e3, E e4, E e5)
      Returns an unmodifiable list containing five elements.
      static <E> java.util.List<E> ofList​(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
      Returns an unmodifiable list containing seven elements.
      static <E> java.util.List<E> ofList​(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
      Returns an unmodifiable list containing eight elements.
      static <E> java.util.List<E> ofList​(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
      Returns an unmodifiable list containing nine elements.
      • Methods inherited from class java.lang.Object

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

      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList()
        Returns an empty unmodifiable list.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> emptyList = Lists.ofList();
         
        Type Parameters:
        E - the element type of the list
        Returns:
        an empty unmodifiable list
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1)
        Returns an unmodifiable list containing one element.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> singleElementList = Lists.ofList("Hello");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the single element
        Returns:
        a List containing the specified element
        Throws:
        java.lang.NullPointerException - if the element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1,
                                                   E e2)
        Returns an unmodifiable list containing two elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> twoElementList = Lists.ofList("Hello", "World");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1,
                                                   E e2,
                                                   E e3)
        Returns an unmodifiable list containing three elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> threeElementList = Lists.ofList("Hello", "World", "Java");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4)
        Returns an unmodifiable list containing four elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> fourElementList = Lists.ofList("Hello", "World", "Java", "Lists");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4,
                                                   E e5)
        Returns an unmodifiable list containing five elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> fiveElementList = Lists.ofList("Hello", "World", "Java", "Lists", "Example");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4,
                                                   E e5,
                                                   E e6,
                                                   E e7)
        Returns an unmodifiable list containing seven elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> sevenElementList = Lists.ofList("Hello", "World", "Java", "Lists", "Example", "Seven", "Elements");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        e7 - the seventh element
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4,
                                                   E e5,
                                                   E e6,
                                                   E e7,
                                                   E e8)
        Returns an unmodifiable list containing eight elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> eightElementList = Lists.ofList("Hello", "World", "Java", "Lists", "Example", "Eight", "Elements", "Demo");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        e7 - the seventh element
        e8 - the eighth element
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E e1,
                                                   E e2,
                                                   E e3,
                                                   E e4,
                                                   E e5,
                                                   E e6,
                                                   E e7,
                                                   E e8,
                                                   E e9)
        Returns an unmodifiable list containing nine elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> nineElementList = Lists.ofList("Hello", "World", "Java", "Lists", "Example", "Nine", "Elements", "Demo", "Test");
         
        Type Parameters:
        E - the List's element type
        Parameters:
        e1 - the first element
        e2 - the second element
        e3 - the third element
        e4 - the fourth element
        e5 - the fifth element
        e6 - the sixth element
        e7 - the seventh element
        e8 - the eighth element
        e9 - the ninth element
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if an element is null
      • ofList

        @Nonnull
        @Immutable
        public static <E> java.util.List<E> ofList​(E... elements)
        Returns an unmodifiable list containing the specified elements.

        The returned list is serializable and implements the RandomAccess interface if the implementation class allows.

        Example Usage

        
             List<String> emptyList = Lists.ofList(); // returns an empty list
             List<String> singleElementList = Lists.ofList("Hello"); // returns a list with one element
             List<String> multiElementList = Lists.ofList("Hello", "World", "Java"); // returns a list with multiple elements
         
        Type Parameters:
        E - the List's element type
        Parameters:
        elements - the elements to be included in the list
        Returns:
        a List containing the specified elements
        Throws:
        java.lang.NullPointerException - if any element is null