Class ListUtils


  • public final class ListUtils
    extends Object
    Useful methods for working with Lists.
    Author:
    Curtis Rueden
    • Method Detail

      • first

        public static <T> T first​(List<T> list)
        Gets the first element of the given list, or null if none.
      • string

        public static String string​(List<?> list)
        Converts the given list to a string.

        The list elements will be separated by a comma then a space. The list will be enclosed in square brackets.

        Parameters:
        list - The list to stringify.
        See Also:
        string(List, String, String, String, boolean)
      • string

        public static String string​(List<?> list,
                                    boolean encloseSingletons)
        Converts the given list to a string.

        The list elements will be separated by a comma then a space. The list will be enclosed in square brackets unless it is a singleton with the encloseSingletons flag set to false.

        Parameters:
        list - The list to stringify.
        encloseSingletons - Whether to enclose singleton lists in brackets.
        Returns:
        The stringified list.
        See Also:
        string(List, String, String, String, boolean)
      • string

        public static String string​(List<?> list,
                                    String lDelimiter,
                                    String rDelimiter,
                                    String separator,
                                    boolean encloseSingletons)
        Converts the given list to a string.

        The list elements will be comma-separated. It will be enclosed in square brackets unless the list is a singleton with the encloseSingletons flag set to false.

        Parameters:
        list - The list to stringify.
        lDelimiter - The left-hand symbol(s) in which to enclose the list.
        rDelimiter - The right-hand symbol(s) in which to enclose the list.
        separator - The symbol(s) to place in between each element.
        encloseSingletons - Whether to enclose singleton lists inside the delimiter symbols.
        Returns:
        The stringified list.