Class ApacheCommonsLangUtil


  • public class ApacheCommonsLangUtil
    extends Object
    Select methods copied from Apache Commons to avoid importing entire lib No changes to logic
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String EMPTY
      The empty String "".
      static int INDEX_NOT_FOUND
      The index value when an element is not found in a list or array: -1.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T[] addAll​(T[] array1, T... array2)
      Adds all the elements of the given arrays into a new array.
      static String capitalize​(String str)
      Capitalizes all the whitespace separated words in a String.
      static String capitalize​(String str, char... delimiters)
      Capitalizes all the delimiter separated words in a String.
      static String capitalizeFully​(String str)
      Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.
      static String capitalizeFully​(String str, char... delimiters)
      Converts all the delimiter separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.
      static <T> T[] clone​(T[] array)
      Shallow clones an array returning a typecast result and handling null.
      static int indexOf​(Object[] array, Object objectToFind)
      Finds the index of the given object in the array.
      static int indexOf​(Object[] array, Object objectToFind, int startIndex)
      Finds the index of the given object in the array starting at the given index.
      static boolean isDelimiter​(char ch, char[] delimiters)
      Is the character a delimiter.
      static boolean isNumeric​(CharSequence cs)
      Checks if the CharSequence contains only Unicode digits.
      static String join​(byte[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(byte[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(char[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(char[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(double[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(double[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(float[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(float[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(int[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(int[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(long[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(long[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(short[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(short[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(Iterable<?> iterable, char separator)
      Joins the elements of the provided Iterable into a single String containing the provided elements.
      static String join​(Iterable<?> iterable, String separator)
      Joins the elements of the provided Iterable into a single String containing the provided elements.
      static String join​(Object[] array, char separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(Object[] array, char separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(Object[] array, String separator)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(Object[] array, String separator, int startIndex, int endIndex)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static String join​(Iterator<?> iterator, char separator)
      Joins the elements of the provided Iterator into a single String containing the provided elements.
      static String join​(Iterator<?> iterator, String separator)
      Joins the elements of the provided Iterator into a single String containing the provided elements.
      static <T> String join​(T... elements)
      Joins the elements of the provided array into a single String containing the provided list of elements.
      static boolean startsWith​(CharSequence str, CharSequence prefix)
      Check if a CharSequence starts with a specified prefix.
      static boolean startsWithIgnoreCase​(CharSequence str, CharSequence prefix)
      Case insensitive check if a CharSequence starts with a specified prefix.
    • Field Detail

      • INDEX_NOT_FOUND

        public static final int INDEX_NOT_FOUND
        The index value when an element is not found in a list or array: -1. This value is returned by methods in this class and can also be used in comparisons with values returned by various method from List.
        See Also:
        Constant Field Values
    • Method Detail

      • clone

        public static <T> T[] clone​(T[] array)

        Shallow clones an array returning a typecast result and handling null.

        The objects in the array are not cloned, thus there is no special handling for multi-dimensional arrays.

        This method returns null for a null input array.

        Type Parameters:
        T - the component type of the array
        Parameters:
        array - the array to shallow clone, may be null
        Returns:
        the cloned array, null if null input
      • addAll

        public static <T> T[] addAll​(T[] array1,
                                     T... array2)

        Adds all the elements of the given arrays into a new array.

        The new array contains all of the element of array1 followed by all of the elements array2. When an array is returned, it is always a new array.

         ArrayUtils.addAll(null, null)     = null
         ArrayUtils.addAll(array1, null)   = cloned copy of array1
         ArrayUtils.addAll(null, array2)   = cloned copy of array2
         ArrayUtils.addAll([], [])         = []
         ArrayUtils.addAll([null], [null]) = [null, null]
         ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"]
         
        Type Parameters:
        T - the component type of the array
        Parameters:
        array1 - the first array whose elements are added to the new array, may be null
        array2 - the second array whose elements are added to the new array, may be null
        Returns:
        The new array, null if both arrays are null. The type of the new array is the type of the first array, unless the first array is null, in which case the type is the same as the second array.
        Throws:
        IllegalArgumentException - if the array types are incompatible
        Since:
        2.1
      • capitalizeFully

        public static String capitalizeFully​(String str)

        Converts all the whitespace separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.

        Whitespace is defined by Character.isWhitespace(char). A null input String returns null. Capitalization uses the Unicode title case, normally equivalent to upper case.

         WordUtils.capitalizeFully(null)        = null
         WordUtils.capitalizeFully("")          = ""
         WordUtils.capitalizeFully("i am FINE") = "I Am Fine"
         
        Parameters:
        str - the String to capitalize, may be null
        Returns:
        capitalized String, null if null String input
      • capitalizeFully

        public static String capitalizeFully​(String str,
                                             char... delimiters)

        Converts all the delimiter separated words in a String into capitalized words, that is each word is made up of a titlecase character and then a series of lowercase characters.

        The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be capitalized.

        A null input String returns null. Capitalization uses the Unicode title case, normally equivalent to upper case.

         WordUtils.capitalizeFully(null, *)            = null
         WordUtils.capitalizeFully("", *)              = ""
         WordUtils.capitalizeFully(*, null)            = *
         WordUtils.capitalizeFully(*, new char[0])     = *
         WordUtils.capitalizeFully("i aM.fine", {'.'}) = "I am.Fine"
         
        Parameters:
        str - the String to capitalize, may be null
        delimiters - set of characters to determine capitalization, null means whitespace
        Returns:
        capitalized String, null if null String input
        Since:
        2.1
      • capitalize

        public static String capitalize​(String str)

        Capitalizes all the whitespace separated words in a String. Only the first character of each word is changed. To convert the rest of each word to lowercase at the same time, use capitalizeFully(String).

        Whitespace is defined by Character.isWhitespace(char). A null input String returns null. Capitalization uses the Unicode title case, normally equivalent to upper case.

         WordUtils.capitalize(null)        = null
         WordUtils.capitalize("")          = ""
         WordUtils.capitalize("i am FINE") = "I Am FINE"
         
        Parameters:
        str - the String to capitalize, may be null
        Returns:
        capitalized String, null if null String input
        See Also:
        capitalizeFully(String)
      • capitalize

        public static String capitalize​(String str,
                                        char... delimiters)

        Capitalizes all the delimiter separated words in a String. Only the first character of each word is changed. To convert the rest of each word to lowercase at the same time, use capitalizeFully(String, char[]).

        The delimiters represent a set of characters understood to separate words. The first string character and the first non-delimiter character after a delimiter will be capitalized.

        A null input String returns null. Capitalization uses the Unicode title case, normally equivalent to upper case.

         WordUtils.capitalize(null, *)            = null
         WordUtils.capitalize("", *)              = ""
         WordUtils.capitalize(*, new char[0])     = *
         WordUtils.capitalize("i am fine", null)  = "I Am Fine"
         WordUtils.capitalize("i aM.fine", {'.'}) = "I aM.Fine"
         
        Parameters:
        str - the String to capitalize, may be null
        delimiters - set of characters to determine capitalization, null means whitespace
        Returns:
        capitalized String, null if null String input
        Since:
        2.1
        See Also:
        capitalizeFully(String)
      • isDelimiter

        public static boolean isDelimiter​(char ch,
                                          char[] delimiters)
        Is the character a delimiter.
        Parameters:
        ch - the character to check
        delimiters - the delimiters
        Returns:
        true if it is a delimiter
      • join

        @SafeVarargs
        public static <T> String join​(T... elements)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No separator is added to the joined String. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null)            = null
         StringUtils.join([])              = ""
         StringUtils.join([null])          = ""
         StringUtils.join(["a", "b", "c"]) = "abc"
         StringUtils.join([null, "", "a"]) = "a"
         
        Type Parameters:
        T - the specific type of values to join together
        Parameters:
        elements - the values to join together, may be null
        Returns:
        the joined String, null if null array input
        Since:
        2.0, 3.0 Changed signature to use varargs
      • join

        public static String join​(Object[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join(["a", "b", "c"], ';')  = "a;b;c"
         StringUtils.join(["a", "b", "c"], null) = "abc"
         StringUtils.join([null, "", "a"], ';')  = ";;a"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        2.0
      • join

        public static String join​(long[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(int[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(short[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(byte[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(char[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(float[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(double[] array,
                                  char separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(Object[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join(["a", "b", "c"], ';')  = "a;b;c"
         StringUtils.join(["a", "b", "c"], null) = "abc"
         StringUtils.join([null, "", "a"], ';')  = ";;a"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        2.0
      • join

        public static String join​(long[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(int[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(byte[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(short[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(char[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(double[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(float[] array,
                                  char separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)               = null
         StringUtils.join([], *)                 = ""
         StringUtils.join([null], *)             = ""
         StringUtils.join([1, 2, 3], ';')  = "1;2;3"
         StringUtils.join([1, 2, 3], null) = "123"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use
        startIndex - the first index to start joining from. It is an error to pass in an end index past the end of the array
        endIndex - the index to stop joining from (exclusive). It is an error to pass in an end index past the end of the array
        Returns:
        the joined String, null if null array input
        Since:
        3.2
      • join

        public static String join​(Object[] array,
                                  String separator)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. A null separator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *)                = null
         StringUtils.join([], *)                  = ""
         StringUtils.join([null], *)              = ""
         StringUtils.join(["a", "b", "c"], "--")  = "a--b--c"
         StringUtils.join(["a", "b", "c"], null)  = "abc"
         StringUtils.join(["a", "b", "c"], "")    = "abc"
         StringUtils.join([null, "", "a"], ',')   = ",,a"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use, null treated as ""
        Returns:
        the joined String, null if null array input
      • join

        public static String join​(Object[] array,
                                  String separator,
                                  int startIndex,
                                  int endIndex)

        Joins the elements of the provided array into a single String containing the provided list of elements.

        No delimiter is added before or after the list. A null separator is the same as an empty String (""). Null objects or empty strings within the array are represented by empty strings.

         StringUtils.join(null, *, *, *)                = null
         StringUtils.join([], *, *, *)                  = ""
         StringUtils.join([null], *, *, *)              = ""
         StringUtils.join(["a", "b", "c"], "--", 0, 3)  = "a--b--c"
         StringUtils.join(["a", "b", "c"], "--", 1, 3)  = "b--c"
         StringUtils.join(["a", "b", "c"], "--", 2, 3)  = "c"
         StringUtils.join(["a", "b", "c"], "--", 2, 2)  = ""
         StringUtils.join(["a", "b", "c"], null, 0, 3)  = "abc"
         StringUtils.join(["a", "b", "c"], "", 0, 3)    = "abc"
         StringUtils.join([null, "", "a"], ',', 0, 3)   = ",,a"
         
        Parameters:
        array - the array of values to join together, may be null
        separator - the separator character to use, null treated as ""
        startIndex - the first index to start joining from.
        endIndex - the index to stop joining from (exclusive).
        Returns:
        the joined String, null if null array input; or the empty string if endIndex - startIndex <= 0. The number of joined entries is given by endIndex - startIndex
        Throws:
        ArrayIndexOutOfBoundsException - ife
        startIndex < 0 or
        startIndex >= array.length() or
        endIndex < 0 or
        endIndex > array.length()
      • join

        public static String join​(Iterator<?> iterator,
                                  char separator)

        Joins the elements of the provided Iterator into a single String containing the provided elements.

        No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.

        See the examples here: join(Object[],char).

        Parameters:
        iterator - the Iterator of values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null iterator input
        Since:
        2.0
      • join

        public static String join​(Iterator<?> iterator,
                                  String separator)

        Joins the elements of the provided Iterator into a single String containing the provided elements.

        No delimiter is added before or after the list. A null separator is the same as an empty String ("").

        See the examples here: join(Object[],String).

        Parameters:
        iterator - the Iterator of values to join together, may be null
        separator - the separator character to use, null treated as ""
        Returns:
        the joined String, null if null iterator input
      • join

        public static String join​(Iterable<?> iterable,
                                  char separator)

        Joins the elements of the provided Iterable into a single String containing the provided elements.

        No delimiter is added before or after the list. Null objects or empty strings within the iteration are represented by empty strings.

        See the examples here: join(Object[],char).

        Parameters:
        iterable - the Iterable providing the values to join together, may be null
        separator - the separator character to use
        Returns:
        the joined String, null if null iterator input
        Since:
        2.3
      • join

        public static String join​(Iterable<?> iterable,
                                  String separator)

        Joins the elements of the provided Iterable into a single String containing the provided elements.

        No delimiter is added before or after the list. A null separator is the same as an empty String ("").

        See the examples here: join(Object[],String).

        Parameters:
        iterable - the Iterable providing the values to join together, may be null
        separator - the separator character to use, null treated as ""
        Returns:
        the joined String, null if null iterator input
        Since:
        2.3
      • isNumeric

        public static boolean isNumeric​(CharSequence cs)

        Checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false.

        null will return false. An empty CharSequence (length()=0) will return false.

        Note that the method does not allow for a leading sign, either positive or negative. Also, if a String passes the numeric test, it may still generate a NumberFormatException when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range for int or long respectively.

         StringUtils.isNumeric(null)   = false
         StringUtils.isNumeric("")     = false
         StringUtils.isNumeric("  ")   = false
         StringUtils.isNumeric("123")  = true
         StringUtils.isNumeric("१२३")  = true
         StringUtils.isNumeric("12 3") = false
         StringUtils.isNumeric("ab2c") = false
         StringUtils.isNumeric("12-3") = false
         StringUtils.isNumeric("12.3") = false
         StringUtils.isNumeric("-123") = false
         StringUtils.isNumeric("+123") = false
         
        Parameters:
        cs - the CharSequence to check, may be null
        Returns:
        true if only contains digits, and is non-null
        Since:
        3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence), 3.0 Changed "" to return false and not true
      • startsWith

        public static boolean startsWith​(CharSequence str,
                                         CharSequence prefix)

        Check if a CharSequence starts with a specified prefix.

        nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive.

         StringUtils.startsWith(null, null)      = true
         StringUtils.startsWith(null, "abc")     = false
         StringUtils.startsWith("abcdef", null)  = false
         StringUtils.startsWith("abcdef", "abc") = true
         StringUtils.startsWith("ABCDEF", "abc") = false
         
        Parameters:
        str - the CharSequence to check, may be null
        prefix - the prefix to find, may be null
        Returns:
        true if the CharSequence starts with the prefix, case sensitive, or both null
        Since:
        2.4, 3.0 Changed signature from startsWith(String, String) to startsWith(CharSequence, CharSequence)
        See Also:
        String.startsWith(String)
      • startsWithIgnoreCase

        public static boolean startsWithIgnoreCase​(CharSequence str,
                                                   CharSequence prefix)

        Case insensitive check if a CharSequence starts with a specified prefix.

        nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case insensitive.

         StringUtils.startsWithIgnoreCase(null, null)      = true
         StringUtils.startsWithIgnoreCase(null, "abc")     = false
         StringUtils.startsWithIgnoreCase("abcdef", null)  = false
         StringUtils.startsWithIgnoreCase("abcdef", "abc") = true
         StringUtils.startsWithIgnoreCase("ABCDEF", "abc") = true
         
        Parameters:
        str - the CharSequence to check, may be null
        prefix - the prefix to find, may be null
        Returns:
        true if the CharSequence starts with the prefix, case insensitive, or both null
        Since:
        2.4, 3.0 Changed signature from startsWithIgnoreCase(String, String) to startsWithIgnoreCase(CharSequence, CharSequence)
        See Also:
        String.startsWith(String)
      • indexOf

        public static int indexOf​(Object[] array,
                                  Object objectToFind)

        Finds the index of the given object in the array.

        This method returns INDEX_NOT_FOUND (-1) for a null input array.

        Parameters:
        array - the array to search through for the object, may be null
        objectToFind - the object to find, may be null
        Returns:
        the index of the object within the array, INDEX_NOT_FOUND (-1) if not found or null array input
      • indexOf

        public static int indexOf​(Object[] array,
                                  Object objectToFind,
                                  int startIndex)

        Finds the index of the given object in the array starting at the given index.

        This method returns INDEX_NOT_FOUND (-1) for a null input array.

        A negative startIndex is treated as zero. A startIndex larger than the array length will return INDEX_NOT_FOUND (-1).

        Parameters:
        array - the array to search through for the object, may be null
        objectToFind - the object to find, may be null
        startIndex - the index to start searching at
        Returns:
        the index of the object within the array starting at the index, INDEX_NOT_FOUND (-1) if not found or null array input