Class StringUtils


  • public final class StringUtils
    extends Object
    This class contains methods used for operations on String type data
    Since:
    1.0.0
    Author:
    Sidhant Agarwal
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String abbreviate​(String sourceString, int maxWidth)
      Abbreviates a String using ellipses
      static String abbreviate​(String sourceString, int offset, int maxWidth)
      Abbreviates a String using ellipses
      static String abbreviate​(String sourceString, String abbrevMarker, int maxWidth)
      Abbreviates a String using another given String as replacement marker
      static String abbreviate​(String sourceString, String abbrevMarker, int offset, int maxWidth)
      Abbreviates a String using a given replacement marker
      static String abbreviateMiddle​(String sourceString, String middle, int length)
      Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement String
      static String appendIfMissing​(String sourceString, CharSequence suffix, CharSequence... suffixes)
      Appends the suffix to the end of the string if the string does not already end with any of the suffixes
      static String appendIfMissingIgnoreCase​(String sourceString, CharSequence suffix, CharSequence... suffixes)
      Appends the suffix to the end of the string if the string does not already end, case insensitive, with any of the suffixes
      static String capitalizeFirstLetter​(String sourceString)
      This method capitalizes the first character of the passed parameter
      static String chomp​(String sourceString)
      Removes one newline from end of a String if it's there, otherwise leave it alone
      static String chop​(String sourceString)
      Remove the last character from a String
      static int compare​(String sourceString1, String sourceString2)
      This method compares two input string
      static int compare​(String sourceString1, String sourceString2, boolean nullIsLess)
      This method compares two Strings lexicographically
      static int compareIgnoreCase​(String sourceString1, String sourceString2)
      This method compares two Strings lexicographically, ignoring case differences
      static int compareIgnoreCase​(String sourceString1, String sourceString2, boolean nullIsLess)  
      static boolean contains​(CharSequence seq, int searchChar)
      This method checks if CharSequence contains a search character, handling null
      static boolean contains​(CharSequence seq, CharSequence searchSeq)
      This method checks if CharSequence contains a search CharSequence, handling null
      static boolean containsIgnoreCase​(CharSequence sourceString, CharSequence searchStr)
      This method checks if CharSequence contains a search CharSequence irrespective of case, handling null.
      static boolean containsWhitespace​(CharSequence seq)
      This method checks whether the given CharSequence contains any whitespace characters
      static int countMatches​(CharSequence sourceString, char ch)
      Counts how many times the char appears in the given string
      static int countMatches​(CharSequence sourceString, CharSequence sub)
      Counts how many times the substring appears in the larger string
      static String deleteWhitespace​(String sourceString)
      Deletes all whitespaces from a String
      static String difference​(String sourceString1, String sourceString2)
      Compares two Strings, and returns the portion where they differ
      static boolean endsWith​(CharSequence sourceString, CharSequence suffix)
      Check if a CharSequence ends with a specified suffix
      static boolean endsWithIgnoreCase​(CharSequence sourceString, CharSequence suffix)
      Case insensitive check if a CharSequence ends with a specified suffix
      static boolean equals​(CharSequence charSeq1, CharSequence charSeq2)
      Compares two CharSequences
      static boolean equalsIgnoreCase​(CharSequence sourceString1, CharSequence sourceString2)
      Compares two CharSequences ignoring case
      static String getDigits​(String sourceString)
      Checks if a String sourceString contains Unicode digits, if yes then concatenate all the digits in sourceString and return it as a String
      static int indexOf​(CharSequence seq, int searchChar)
      Returns the index within seq of the first occurrence of the specified character
      static int indexOf​(CharSequence seq, int searchChar, int startPos)
      Returns the index within seq of the first occurrence of the specified character, starting the search at the specified index
      static int indexOf​(CharSequence seq, CharSequence searchSeq)
      Finds the first index within a CharSequence, handling null
      static int indexOf​(CharSequence seq, CharSequence searchSeq, int startPos)
      Finds the first index within a CharSequence, handling null
      static boolean isAllLowerCase​(CharSequence charSeq)
      Checks if the CharSequence contains only lowercase characters
      static boolean isAllUpperCase​(CharSequence charSeq)
      Checks if the CharSequence contains only uppercase characters
      static boolean isAlpha​(CharSequence charSeq)
      Checks if the CharSequence contains only Unicode letters
      static boolean isAlphanumeric​(CharSequence charSeq)
      Checks if the CharSequence contains only Unicode letters or digits
      static boolean isAlphanumericSpace​(CharSequence charSeq)
      Checks if the CharSequence contains only Unicode letters, digits or space (' ')
      static boolean isAlphaSpace​(CharSequence charSeq)
      Checks if the CharSequence contains only Unicode letters and space (' ')
      static boolean isBlank​(CharSequence charSeq)
      This method checks if a CharSequence is empty (""), null or whitespace only
      static boolean isEmpty​(CharSequence charSeq)
      This method checks if a CharSequence is empty ("") or null
      static boolean isMixedCase​(CharSequence charSeq)
      Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters
      static boolean isNotBlank​(CharSequence charSeq)
      This method checks if a CharSequence is not empty (""), not null and not whitespace only
      static boolean isNotEmpty​(CharSequence charSeq)
      This method checks if a CharSequence is not empty ("") and not null
      static boolean isNumeric​(CharSequence charSeq)
      Checks if the CharSequence contains only Unicode digits.
      static boolean isNumericSpace​(CharSequence charSeq)
      Checks if the CharSequence contains only Unicode digits or space (' ').
      static boolean isWhitespace​(CharSequence charSeq)
      Checks if the CharSequence contains only whitespace
      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​(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 int lastIndexOf​(CharSequence seq, int searchChar)
      Returns the index within seq of the last occurrence of the specified character
      static int lastIndexOf​(CharSequence seq, int searchChar, int startPos)
      Returns the index within seq of the last occurrence of the specified character, searching backward starting at the specified index
      static int lastIndexOf​(CharSequence seq, CharSequence searchSeq)
      Finds the last index within a CharSequence, handling null
      static int lastIndexOf​(CharSequence seq, CharSequence searchSeq, int startPos)
      Finds the last index within a CharSequence, handling null
      static int length​(CharSequence charSeq)
      String with repeated character
      static String lowerCase​(String sourceString)
      CharSequence length or 0 if the CharSequence is null
      static String lowerCase​(String sourceString, Locale locale)
      Converts a String to local case
      static String normalizeSpace​(String sourceString)
      Returns the argument string with whitespace normalized
      static String overlay​(String sourceString, String overlay, int start, int end)
      Overlays part of a String with another String
      static String prependIfMissing​(String sourceString, CharSequence prefix, CharSequence... prefixes)
      Prepends the prefix to the start of the string if the string does not already start with any of the prefixes
      static String prependIfMissingIgnoreCase​(String sourceString, CharSequence prefix, CharSequence... prefixes)
      Prepends the prefix to the start of the string if the string does not already start, case insensitive, with any of the prefixes
      static String remove​(String sourceString, char remove)
      Removes all occurrences of a character from within the source string
      static String remove​(String sourceString, String remove)
      Removes all occurrences of a substring from within the source string
      static String removeAll​(String text, String regex)
      Removes each substring of the text String that matches the given regular expression
      static String removeIgnoreCase​(String sourceString, String remove)
      Case insensitive removal of all occurrences of a substring from within the source string
      static String removeLeftChar​(String sourceString, int len)
      Gets the leftmost len characters of a String
      static String removeMidChar​(String sourceString, int pos, int len)
      Gets len characters from the middle of a String
      static String removePattern​(String source, String regex)
      Removes each substring of the source String that matches the given regular expression
      static String removeRightChar​(String sourceString, int len)
      Gets the rightmost len characters of a String
      static String repeat​(char ch, int repeat)
      Returns padding using the specified delimiter repeated to a given length
      static String repeat​(String sourceString, int repeat)
      Repeat a String repeat times to form a new String
      static String repeat​(String sourceString, String separator, int repeat)
      Repeat a String repeat times to form a new String, with a String separator injected each time
      static String replace​(String text, String searchString, String replacement)
      Replaces all occurrences of a String within another String
      static String replace​(String text, String searchString, String replacement, int max)
      Replaces a String with another String inside a larger String, for the first max values of the search String
      static String replaceAll​(String text, String regex, String replacement)
      Replaces each substring of the text String that matches the given regular expression with the given replacement
      static String replaceChars​(String sourceString, char searchChar, char replaceChar)
      Replaces all occurrences of a character in a String with another
      static String replaceChars​(String sourceString, String searchChars, String replaceChars)
      Replaces multiple characters in a String in one go(can also be used to delete characters)
      static String replaceIgnoreCase​(String text, String searchString, String replacement)
      Case insensitively replaces all occurrences of a String within another String
      static String replaceIgnoreCase​(String text, String searchString, String replacement, int max)
      Case insensitively replaces a String with another String inside a larger String, for the first max values of the search String
      static String replaceOnce​(String text, String searchString, String replacement)
      Replaces a String with another String inside a larger String, once
      static String replaceOnceIgnoreCase​(String text, String searchString, String replacement)
      Case insensitively replaces a String with another String inside a larger String, once
      static String replacePattern​(String source, String regex, String replacement)
      Replaces each substring of the source String that matches the given regular expression with the given replacement
      static String reverse​(String sourceString)
      Reverses a String
      static String reverseDelimited​(String sourceString, char separatorChar)
      Reverses a String that is delimited by a specific character
      static String rotate​(String sourceString, int shift)
      Rotate (circular shift) a String of shift characters
      static String[] split​(String sourceString)
      Splits the provided text into an array, using whitespace as the separator
      static String[] split​(String sourceString, char separatorChar)
      Splits the provided text into an array, separator specified
      static String[] splitByCharacterType​(String sourceString)
      Splits a String by Character type
      static String[] splitByCharacterTypeCamelCase​(String sourceString)
      Splits a String by Character type
      static boolean startsWith​(CharSequence sourceString, CharSequence prefix)
      Check if a CharSequence starts with a specified prefix
      static boolean startsWithIgnoreCase​(CharSequence sourceString, CharSequence prefix)
      Case insensitive check if a CharSequence starts with a specified prefix
      static String strip​(String sourceString)
      Strips whitespace from the start and end of a String
      static String strip​(String sourceString, String stripChars)
      Strips any of a set of characters from the start and end of a String
      static String substring​(String sourceString, int start)
      Gets a substring from the specified String avoiding exceptions.
      static String substring​(String sourceString, int start, int end)
      Gets a substring from the specified String avoiding exceptions
      static String substringAfter​(String sourceString, String separator)
      Gets the substring after the first occurrence of a separator
      static String substringBefore​(String sourceString, String separator)
      Gets the substring before the first occurrence of a separator
      static String swapCase​(String sourceString)
      Swaps the case of a String changing upper and title case to lower case, and lower case to upper case
      static String trim​(String sourceString)
      This method removes control characters (char is less than= 32) from both ends of this String, handling null by returning null
      static String truncate​(String sourceString, int maxWidth)
      Truncates a String
      static String truncate​(String sourceString, int offset, int maxWidth)
      Truncates a String
      static String uncapitalize​(String sourceString)
      Uncapitalizes a String, changing the first character to lower case
      static String unwrap​(String sourceString, char wrapChar)
      Unwraps a given string from a character
      static String unwrap​(String sourceString, String wrapToken)
      Unwraps a given string from anther string
      static String upperCase​(String sourceString)
      CharSequence length or 0 if the CharSequence is null
      static String upperCase​(String sourceString, Locale locale)
      Converts a String to upper case
      static String wrap​(String sourceString, char wrapWith)
      Wraps a string with a char
      static String wrap​(String sourceString, String wrapWith)
      Wraps a String with another String
      static String wrapIfMissing​(String sourceString, char wrapWith)
      Wraps a string with a char if that char is missing from the start or end of the given string
      static String wrapIfMissing​(String sourceString, String wrapWith)
      Wraps a string with a string if that string is missing from the start or end of the given string
    • Method Detail

      • capitalizeFirstLetter

        public static String capitalizeFirstLetter​(String sourceString)
        This method capitalizes the first character of the passed parameter
        Parameters:
        sourceString - input string
        Returns:
        String changing the first character to UpperCase
      • compare

        public static int compare​(String sourceString1,
                                  String sourceString2)
        This method compares two input string
        Parameters:
        sourceString1 - String value
        sourceString2 - String value
        Returns:
        0 if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
      • compare

        public static int compare​(String sourceString1,
                                  String sourceString2,
                                  boolean nullIsLess)
        This method compares two Strings lexicographically
        Parameters:
        sourceString1 - String to compare from
        sourceString2 - String to compare to
        nullIsLess - whether consider null value less than non-null value
        Returns:
        = 0, if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
      • compareIgnoreCase

        public static int compareIgnoreCase​(String sourceString1,
                                            String sourceString2)
        This method compares two Strings lexicographically, ignoring case differences
        Parameters:
        sourceString1 - String to compare from
        sourceString2 - String to compare to
        Returns:
        = 0, if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
      • compareIgnoreCase

        public static int compareIgnoreCase​(String sourceString1,
                                            String sourceString2,
                                            boolean nullIsLess)
        Parameters:
        sourceString1 - String to compare from
        sourceString2 - String to compare to
        nullIsLess - whether consider null value less than non-null value
        Returns:
        = 0, if sourceString1 is equal to sourceString2 (or both null) is less than 0, if sourceString1 is less than sourceString2 is greater than 0, if sourceString1 is greater than sourceString2
      • contains

        public static boolean contains​(CharSequence seq,
                                       CharSequence searchSeq)
        This method checks if CharSequence contains a search CharSequence, handling null
        Parameters:
        seq - the CharSequence to check, may be null
        searchSeq - the CharSequence to find, may be null
        Returns:
        true if the CharSequence contains the search CharSequence false if not or null string input
      • contains

        public static boolean contains​(CharSequence seq,
                                       int searchChar)
        This method checks if CharSequence contains a search character, handling null
        Parameters:
        seq - the CharSequence to check, may be null
        searchChar - the character to find
        Returns:
        true if the CharSequence contains the search CharSequence false if not or null string input
      • containsIgnoreCase

        public static boolean containsIgnoreCase​(CharSequence sourceString,
                                                 CharSequence searchStr)
        This method checks if CharSequence contains a search CharSequence irrespective of case, handling null.
        Parameters:
        sourceString - the CharSequence to check, may be null
        searchStr - the CharSequence to find, may be null
        Returns:
        true if the CharSequence contains the search CharSequence irrespective of case false if not or null string input
      • containsWhitespace

        public static boolean containsWhitespace​(CharSequence seq)
        This method checks whether the given CharSequence contains any whitespace characters
        Parameters:
        seq - the CharSequence to check (may be null)
        Returns:
        true if the CharSequence is not empty and contains at least 1 (breaking) whitespace character false if no whitespace is present
      • isEmpty

        public static boolean isEmpty​(CharSequence charSeq)
        This method checks if a CharSequence is empty ("") or null
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if the CharSequence is empty or null
      • isNotEmpty

        public static boolean isNotEmpty​(CharSequence charSeq)
        This method checks if a CharSequence is not empty ("") and not null
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if the CharSequence is not empty and not null
      • isBlank

        public static boolean isBlank​(CharSequence charSeq)
        This method checks if a CharSequence is empty (""), null or whitespace only
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if the CharSequence is null, empty or whitespace only
      • isNotBlank

        public static boolean isNotBlank​(CharSequence charSeq)
        This method checks if a CharSequence is not empty (""), not null and not whitespace only
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if the CharSequence is not empty and not null and not whitespace only
      • trim

        public static String trim​(String sourceString)
        This method removes control characters (char is less than= 32) from both ends of this String, handling null by returning null
        Parameters:
        sourceString - the String to be trimmed, may be null
        Returns:
        the trimmed string null, if null String input
      • truncate

        public static String truncate​(String sourceString,
                                      int maxWidth)
        Truncates a String
        Parameters:
        sourceString - the String to truncate, may be null
        maxWidth - maximum length of result String, must be positive
        Returns:
        truncated String, null if null String input
      • truncate

        public static String truncate​(String sourceString,
                                      int offset,
                                      int maxWidth)
        Truncates a String
        Parameters:
        sourceString - the String to check, may be null
        offset - left edge of source String
        maxWidth - maximum length of result String, must be positive
        Returns:
        truncated String, null if null String input
      • strip

        public static String strip​(String sourceString)
        Strips whitespace from the start and end of a String
        Parameters:
        sourceString - the String to remove whitespace from, may be null
        Returns:
        the stripped String, null if null String input
      • strip

        public static String strip​(String sourceString,
                                   String stripChars)
        Strips any of a set of characters from the start and end of a String
        Parameters:
        sourceString - the String to remove characters from, may be null
        stripChars - the characters to remove, null treated as whitespace
        Returns:
        the stripped String null if null String input
      • equals

        public static boolean equals​(CharSequence charSeq1,
                                     CharSequence charSeq2)
        Compares two CharSequences
        Parameters:
        charSeq1 - the first CharSequence, may be null
        charSeq2 - charSeq2 the second CharSequence, may be null
        Returns:
        true if the CharSequences are equal (case-sensitive), or both null
      • equalsIgnoreCase

        public static boolean equalsIgnoreCase​(CharSequence sourceString1,
                                               CharSequence sourceString2)
        Compares two CharSequences ignoring case
        Parameters:
        sourceString1 - the first CharSequence, may be null
        sourceString2 - the second CharSequence, may be null
        Returns:
        true if the CharSequence are equal, case insensitive, or both null
      • indexOf

        public static int indexOf​(CharSequence seq,
                                  int searchChar)
        Returns the index within seq of the first occurrence of the specified character
        Parameters:
        seq - the CharSequence to check, may be null
        searchChar - the character to find
        Returns:
        the first index of the search character, -1 if no match or null string input
      • indexOf

        public static int indexOf​(CharSequence seq,
                                  int searchChar,
                                  int startPos)
        Returns the index within seq of the first occurrence of the specified character, starting the search at the specified index
        Parameters:
        seq - the CharSequence to check, may be null
        searchChar - the character to find
        startPos - the start position, negative treated as zero
        Returns:
        the first index of the search character (always ≥ startPos), -1 if no match or null string input
      • indexOf

        public static int indexOf​(CharSequence seq,
                                  CharSequence searchSeq)
        Finds the first index within a CharSequence, handling null
        Parameters:
        seq - the CharSequence to check, may be null
        searchSeq - the CharSequence to find, may be null
        Returns:
        the first index of the search CharSequence, -1 if no match or null string input
      • indexOf

        public static int indexOf​(CharSequence seq,
                                  CharSequence searchSeq,
                                  int startPos)
        Finds the first index within a CharSequence, handling null
        Parameters:
        seq - the CharSequence to check, may be null
        searchSeq - the CharSequence to find, may be null
        startPos - the start position, negative treated as zero
        Returns:
        the first index of the search CharSequence (always ≥ startPos), -1 if no match or null string input
      • lastIndexOf

        public static int lastIndexOf​(CharSequence seq,
                                      int searchChar)
        Returns the index within seq of the last occurrence of the specified character
        Parameters:
        seq - the CharSequence to check, may be null
        searchChar - the character to find
        Returns:
        the last index of the search character, -1 if no match or null string input
      • lastIndexOf

        public static int lastIndexOf​(CharSequence seq,
                                      int searchChar,
                                      int startPos)
        Returns the index within seq of the last occurrence of the specified character, searching backward starting at the specified index
        Parameters:
        seq - the CharSequence to check, may be null
        searchChar - the character to find
        startPos - the start position
        Returns:
        the last index of the search character (always ≤ startPos), -1 if no match or null string input
      • lastIndexOf

        public static int lastIndexOf​(CharSequence seq,
                                      CharSequence searchSeq)
        Finds the last index within a CharSequence, handling null
        Parameters:
        seq - the CharSequence to check, may be null
        searchSeq - the CharSequence to find, may be null
        Returns:
        the last index of the search String, -1 if no match or null string input
      • lastIndexOf

        public static int lastIndexOf​(CharSequence seq,
                                      CharSequence searchSeq,
                                      int startPos)
        Finds the last index within a CharSequence, handling null
        Parameters:
        seq - the CharSequence to check, may be null
        searchSeq - the CharSequence to find, may be null
        startPos - the start position, negative treated as zero
        Returns:
        the last index of the search CharSequence (always ≤ startPos), -1 if no match or null string input
      • substring

        public static String substring​(String sourceString,
                                       int start)
        Gets a substring from the specified String avoiding exceptions.
        Parameters:
        sourceString - the String to get the substring from, may be null
        start - the position to start from, negative means count back from the end of the String by this many characters
        Returns:
        substring from start position, null if null String input
      • substring

        public static String substring​(String sourceString,
                                       int start,
                                       int end)
        Gets a substring from the specified String avoiding exceptions
        Parameters:
        sourceString - the String to get the substring from, may be null
        start - the position to start from, negative means count back from the end of the String by this many characters
        end - the position to end at (exclusive), negative means count back from the end of the String by this many characters
        Returns:
        substring from start position to end position, null if null String input
      • removeLeftChar

        public static String removeLeftChar​(String sourceString,
                                            int len)
        Gets the leftmost len characters of a String
        Parameters:
        sourceString - the String to get the leftmost characters from, may be null
        len - the length of the required String
        Returns:
        the leftmost characters, null if null String input
      • removeRightChar

        public static String removeRightChar​(String sourceString,
                                             int len)
        Gets the rightmost len characters of a String
        Parameters:
        sourceString - the String to get the rightmost characters from, may be null
        len - the length of the required String
        Returns:
        the rightmost characters, null if null String input
      • removeMidChar

        public static String removeMidChar​(String sourceString,
                                           int pos,
                                           int len)
        Gets len characters from the middle of a String
        Parameters:
        sourceString - the String to get the characters from, may be null
        pos - the position to start from, negative treated as zero
        len - len the length of the required String
        Returns:
        the middle characters, null if null String input
      • substringBefore

        public static String substringBefore​(String sourceString,
                                             String separator)
        Gets the substring before the first occurrence of a separator
        Parameters:
        sourceString - the String to get a substring from, may be null
        separator - the String to search for, may be null
        Returns:
        the substring before the first occurrence of the separator, null if null String input
      • substringAfter

        public static String substringAfter​(String sourceString,
                                            String separator)
        Gets the substring after the first occurrence of a separator
        Parameters:
        sourceString - the String to get a substring from, may be null
        separator - the String to search for, may be null
        Returns:
        substring after the first occurrence of the separator, null if null String input
      • split

        public static String[] split​(String sourceString)
        Splits the provided text into an array, using whitespace as the separator
        Parameters:
        sourceString - String to parse, may be null
        Returns:
        array of parsed Strings, null if null String input
      • split

        public static String[] split​(String sourceString,
                                     char separatorChar)
        Splits the provided text into an array, separator specified
        Parameters:
        sourceString - the String to parse, may be null
        separatorChar - the character used as the delimiter
        Returns:
        an array of parsed Strings, null if null String input
      • splitByCharacterType

        public static String[] splitByCharacterType​(String sourceString)
        Splits a String by Character type
        Parameters:
        sourceString - the String to split, may be null
        Returns:
        an array of parsed Strings, null if null String input
      • splitByCharacterTypeCamelCase

        public static String[] splitByCharacterTypeCamelCase​(String sourceString)
        Splits a String by Character type
        Parameters:
        sourceString - the String to split, may be null
        Returns:
        an array of parsed Strings, null if null String input
      • 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
        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
      • 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
        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
      • 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
        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
      • 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
        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
      • 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
        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
      • 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
        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
      • 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
        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
      • 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
        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
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • 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
        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
        Throws:
        ArrayIndexOutOfBoundsException - - if startIndex and endIndex are not valid positions
      • deleteWhitespace

        public static String deleteWhitespace​(String sourceString)
        Deletes all whitespaces from a String
        Parameters:
        sourceString - the String to delete whitespace from, may be null
        Returns:
        the String without whitespaces, null if null String input
      • remove

        public static String remove​(String sourceString,
                                    String remove)
        Removes all occurrences of a substring from within the source string
        Parameters:
        sourceString - the source String to search, may be null
        remove - the String to search for and remove, may be null
        Returns:
        the substring with the string removed if found, null if null String input
      • removeIgnoreCase

        public static String removeIgnoreCase​(String sourceString,
                                              String remove)
        Case insensitive removal of all occurrences of a substring from within the source string
        Parameters:
        sourceString - the source String to search, may be null
        remove - the String to search for (case insensitive) and remove, may be null
        Returns:
        the substring with the string removed if found, null if null String input
      • remove

        public static String remove​(String sourceString,
                                    char remove)
        Removes all occurrences of a character from within the source string
        Parameters:
        sourceString - the source String to search, may be null
        remove - the char to search for and remove, may be null
        Returns:
        the substring with the char removed if found, null if null String input
      • removeAll

        public static String removeAll​(String text,
                                       String regex)
        Removes each substring of the text String that matches the given regular expression
        Parameters:
        text - text to remove from, may be null
        regex - the regular expression to which this string is to be matched
        Returns:
        the text with any removes processed, null if null String input
        Throws:
        PatternSyntaxException - - if the regular expression's syntax is invalid
      • replaceOnce

        public static String replaceOnce​(String text,
                                         String searchString,
                                         String replacement)
        Replaces a String with another String inside a larger String, once
        Parameters:
        text - text to search and replace in, may be null
        searchString - the String to search for, may be null
        replacement - the String to replace with, may be null
        Returns:
        the text with any replacements processed, null if null String input
      • replaceOnceIgnoreCase

        public static String replaceOnceIgnoreCase​(String text,
                                                   String searchString,
                                                   String replacement)
        Case insensitively replaces a String with another String inside a larger String, once
        Parameters:
        text - text to search and replace in, may be null
        searchString - the String to search for (case insensitive), may be null
        replacement - the String to replace with, may be null
        Returns:
        the text with any replacements processed, null if null String input
      • replacePattern

        public static String replacePattern​(String source,
                                            String regex,
                                            String replacement)
        Replaces each substring of the source String that matches the given regular expression with the given replacement
        Parameters:
        source - the source string
        regex - the regular expression to which this string is to be matched
        replacement - the string to be substituted for each match
        Returns:
        The resulting replaced String
        Throws:
        PatternSyntaxException - - if the regular expression's syntax is invalid
      • removePattern

        public static String removePattern​(String source,
                                           String regex)
        Removes each substring of the source String that matches the given regular expression
        Parameters:
        source - the source string
        regex - the regular expression to which this string is to be matched
        Returns:
        The resulting String
        Throws:
        PatternSyntaxException - - if the regular expression's syntax is invalid
      • replaceAll

        public static String replaceAll​(String text,
                                        String regex,
                                        String replacement)
        Replaces each substring of the text String that matches the given regular expression with the given replacement
        Parameters:
        text - text to search and replace in, may be null
        regex - the regular expression to which this string is to be matched
        replacement - the string to be substituted for each match
        Returns:
        the text with any replacements processed, null if null String input
        Throws:
        PatternSyntaxException - if the regular expression's syntax is invalid
      • replace

        public static String replace​(String text,
                                     String searchString,
                                     String replacement)
        Replaces all occurrences of a String within another String
        Parameters:
        text - text to search and replace in, may be null
        searchString - the String to search for, may be null
        replacement - the String to replace it with, may be null
        Returns:
        the text with any replacements processed, null if null String input
      • replaceIgnoreCase

        public static String replaceIgnoreCase​(String text,
                                               String searchString,
                                               String replacement)
        Case insensitively replaces all occurrences of a String within another String
        Parameters:
        text - text to search and replace in, may be null
        searchString - the String to search for (case insensitive), may be null
        replacement - the String to replace it with, may be null
        Returns:
        the text with any replacements processed, null if null String input
      • replace

        public static String replace​(String text,
                                     String searchString,
                                     String replacement,
                                     int max)
        Replaces a String with another String inside a larger String, for the first max values of the search String
        Parameters:
        text - text to search and replace in, may be null
        searchString - the String to search for, may be null
        replacement - the String to replace it with, may be null
        max - maximum number of values to replace, or -1 if no maximum
        Returns:
        the text with any replacements processed, null if null String input
      • replaceIgnoreCase

        public static String replaceIgnoreCase​(String text,
                                               String searchString,
                                               String replacement,
                                               int max)
        Case insensitively replaces a String with another String inside a larger String, for the first max values of the search String
        Parameters:
        text - text to search and replace in, may be null
        searchString - the String to search for (case insensitive), may be null
        replacement - the String to replace it with, may be null
        max - maximum number of values to replace, or -1 if no maximum
        Returns:
        the text with any replacements processed, null if null String input
      • replaceChars

        public static String replaceChars​(String sourceString,
                                          char searchChar,
                                          char replaceChar)
        Replaces all occurrences of a character in a String with another
        Parameters:
        sourceString - String to replace characters in, may be null
        searchChar - the character to search for, may be null
        replaceChar - the character to replace, may be null
        Returns:
        modified String, null if null string input
      • replaceChars

        public static String replaceChars​(String sourceString,
                                          String searchChars,
                                          String replaceChars)
        Replaces multiple characters in a String in one go(can also be used to delete characters)
        Parameters:
        sourceString - String to replace characters in, may be null
        searchChars - a set of characters to search for, may be null
        replaceChars - a set of characters to replace, may be null
        Returns:
        modified String, null if null string inputSince:
      • overlay

        public static String overlay​(String sourceString,
                                     String overlay,
                                     int start,
                                     int end)
        Overlays part of a String with another String
        Parameters:
        sourceString - the String to do overlaying in, may be null
        overlay - the String to overlay, may be null
        start - the position to start overlaying at
        end - the position to stop overlaying before
        Returns:
        overlayed String, null if null String input
      • chomp

        public static String chomp​(String sourceString)
        Removes one newline from end of a String if it's there, otherwise leave it alone
        Parameters:
        sourceString - the String to chomp a newline from, may be null
        Returns:
        String without newline, null if null String input
      • chop

        public static String chop​(String sourceString)
        Remove the last character from a String
        Parameters:
        sourceString - the String to chop last character from, may be null
        Returns:
        String without last character, null if null String input
      • repeat

        public static String repeat​(String sourceString,
                                    int repeat)
        Repeat a String repeat times to form a new String
        Parameters:
        sourceString - the String to repeat, may be null
        repeat - number of times to repeat sourceString, negative treated as zero
        Returns:
        a new String consisting of the original String repeated, null if null String input
      • repeat

        public static String repeat​(String sourceString,
                                    String separator,
                                    int repeat)
        Repeat a String repeat times to form a new String, with a String separator injected each time
        Parameters:
        sourceString - the String to repeat, may be null
        separator - the String to inject, may be null
        repeat - number of times to repeat sourceString, negative treated as zero
        Returns:
        a new String consisting of the original String repeated, null if null String input
      • repeat

        public static String repeat​(char ch,
                                    int repeat)
        Returns padding using the specified delimiter repeated to a given length
        Parameters:
        ch - character to repeat
        repeat - number of times to repeat char, negative treated as zeroReturns:
        Returns:
        String with repeated character
      • length

        public static int length​(CharSequence charSeq)
        String with repeated character
        Parameters:
        charSeq - a CharSequence or null
        Returns:
        CharSequence length or 0 if the CharSequence is null
      • upperCase

        public static String upperCase​(String sourceString)
        CharSequence length or 0 if the CharSequence is null
        Parameters:
        sourceString - the String to upper case, may be null
        Returns:
        the upper cased String, null if null String input
      • upperCase

        public static String upperCase​(String sourceString,
                                       Locale locale)
        Converts a String to upper case
        Parameters:
        sourceString - the String to upper case, may be null
        locale - the locale that defines the case transformation rules, must not be null
        Returns:
        the upper cased String, null if null String inputSince:
      • lowerCase

        public static String lowerCase​(String sourceString)
        CharSequence length or 0 if the CharSequence is null
        Parameters:
        sourceString - the String to lower case, may be null
        Returns:
        the lower cased String, null if null String input
      • lowerCase

        public static String lowerCase​(String sourceString,
                                       Locale locale)
        Converts a String to local case
        Parameters:
        sourceString - the String to local case, may be null
        locale - the locale that defines the case transformation rules, must not be null
        Returns:
        the local cased String, null if null String inputSince:
      • uncapitalize

        public static String uncapitalize​(String sourceString)
        Uncapitalizes a String, changing the first character to lower case
        Parameters:
        sourceString - the String to uncapitalize, may be null
        Returns:
        the uncapitalized String, null if null String input
      • swapCase

        public static String swapCase​(String sourceString)
        Swaps the case of a String changing upper and title case to lower case, and lower case to upper case
        Parameters:
        sourceString - the String to swap case, may be null
        Returns:
        the changed String, null if null String input
      • countMatches

        public static int countMatches​(CharSequence sourceString,
                                       CharSequence sub)
        Counts how many times the substring appears in the larger string
        Parameters:
        sourceString - the CharSequence to check, may be null
        sub - the substring to count, may be null
        Returns:
        the number of occurrences, 0 if either CharSequence is null
      • countMatches

        public static int countMatches​(CharSequence sourceString,
                                       char ch)
        Counts how many times the char appears in the given string
        Parameters:
        sourceString - the CharSequence to check, may be null
        ch - the char to count
        Returns:
        the number of occurrences, 0 if the CharSequence is null
      • isAlpha

        public static boolean isAlpha​(CharSequence charSeq)
        Checks if the CharSequence contains only Unicode letters
        Parameters:
        charSeq - charSeq the CharSequence to check, may be null
        Returns:
        true if only contains letters, and is non-null
      • isAlphaSpace

        public static boolean isAlphaSpace​(CharSequence charSeq)
        Checks if the CharSequence contains only Unicode letters and space (' ')
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains letters and space, and is non-null
      • isAlphanumeric

        public static boolean isAlphanumeric​(CharSequence charSeq)
        Checks if the CharSequence contains only Unicode letters or digits
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains letters or digits, and is non-null
      • isAlphanumericSpace

        public static boolean isAlphanumericSpace​(CharSequence charSeq)
        Checks if the CharSequence contains only Unicode letters, digits or space (' ')
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains letters, digits or space, and is non-null
      • isNumeric

        public static boolean isNumeric​(CharSequence charSeq)
        Checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains digits, and is non-null
      • isNumericSpace

        public static boolean isNumericSpace​(CharSequence charSeq)
        Checks if the CharSequence contains only Unicode digits or space (' '). A decimal point is not a Unicode digit and returns false
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains digits or space, and is non-null
      • getDigits

        public static String getDigits​(String sourceString)
        Checks if a String sourceString contains Unicode digits, if yes then concatenate all the digits in sourceString and return it as a String
        Parameters:
        sourceString - the String to extract digits from, may be null
        Returns:
        String with only digits, or an empty ("") String if no digits found, or null String if sourceString is null
      • isWhitespace

        public static boolean isWhitespace​(CharSequence charSeq)
        Checks if the CharSequence contains only whitespace
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains whitespace, and is non-null
      • isAllLowerCase

        public static boolean isAllLowerCase​(CharSequence charSeq)
        Checks if the CharSequence contains only lowercase characters
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains lowercase characters, and is non-null
      • isAllUpperCase

        public static boolean isAllUpperCase​(CharSequence charSeq)
        Checks if the CharSequence contains only uppercase characters
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if only contains uppercase characters, and is non-null
      • isMixedCase

        public static boolean isMixedCase​(CharSequence charSeq)
        Checks if the CharSequence contains mixed casing of both uppercase and lowercase characters
        Parameters:
        charSeq - the CharSequence to check, may be null
        Returns:
        true if the CharSequence contains both uppercase and lowercase characters
      • rotate

        public static String rotate​(String sourceString,
                                    int shift)
        Rotate (circular shift) a String of shift characters
        Parameters:
        sourceString - the String to rotate, may be null
        shift - number of time to shift (positive : right shift, negative : left shift)
        Returns:
        the rotated String, or the original String if shift == 0, or null if null String input
      • reverse

        public static String reverse​(String sourceString)
        Reverses a String
        Parameters:
        sourceString - the String to reverse, may be null
        Returns:
        the reversed String, null if null String input
      • reverseDelimited

        public static String reverseDelimited​(String sourceString,
                                              char separatorChar)
        Reverses a String that is delimited by a specific character
        Parameters:
        sourceString - the String to reverse, may be null
        separatorChar - the separator character to use
        Returns:
        the reversed String, null if null String input
      • abbreviate

        public static String abbreviate​(String sourceString,
                                        int maxWidth)
        Abbreviates a String using ellipses
        Parameters:
        sourceString - the String to check, may be null
        maxWidth - maximum length of result String, must be at least 4
        Returns:
        abbreviated String, null if null String input
        Throws:
        IllegalArgumentException - - if the width is too small
      • abbreviate

        public static String abbreviate​(String sourceString,
                                        int offset,
                                        int maxWidth)
        Abbreviates a String using ellipses
        Parameters:
        sourceString - the String to check, may be null
        offset - left edge of source String
        maxWidth - maximum length of result String, must be at least 4
        Returns:
        abbreviated String, null if null String input
        Throws:
        IllegalArgumentException - - if the width is too small
      • abbreviate

        public static String abbreviate​(String sourceString,
                                        String abbrevMarker,
                                        int maxWidth)
        Abbreviates a String using another given String as replacement marker
        Parameters:
        sourceString - the String to check, may be null
        abbrevMarker - the String used as replacement marker
        maxWidth - maximum length of result String, must be at least abbrevMarker.length + 1
        Returns:
        abbreviated String, null if null String input
        Throws:
        IllegalArgumentException - - if the width is too small
      • abbreviate

        public static String abbreviate​(String sourceString,
                                        String abbrevMarker,
                                        int offset,
                                        int maxWidth)
        Abbreviates a String using a given replacement marker
        Parameters:
        sourceString - the String to check, may be null
        abbrevMarker - the String used as replacement marker
        offset - left edge of source String
        maxWidth - maximum length of result String, must be at least 4
        Returns:
        abbreviated String, null if null String input
        Throws:
        IllegalArgumentException - - if the width is too small
      • abbreviateMiddle

        public static String abbreviateMiddle​(String sourceString,
                                              String middle,
                                              int length)
        Abbreviates a String to the length passed, replacing the middle characters with the supplied replacement String
        Parameters:
        sourceString - the String to check, may be null
        middle - the String to replace the middle characters with, may be null
        length - the length to abbreviate str to
        Returns:
        the abbreviated String if the above criteria is met, or the original String supplied for abbreviation
      • difference

        public static String difference​(String sourceString1,
                                        String sourceString2)
        Compares two Strings, and returns the portion where they differ
        Parameters:
        sourceString1 - the first String, may be null
        sourceString2 - the second String, may be null
        Returns:
        the portion of sourceString2 where it differs from sourceString1; returns the empty String if they are equal
      • startsWith

        public static boolean startsWith​(CharSequence sourceString,
                                         CharSequence prefix)
        Check if a CharSequence starts with a specified prefix
        Parameters:
        sourceString - 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
      • startsWithIgnoreCase

        public static boolean startsWithIgnoreCase​(CharSequence sourceString,
                                                   CharSequence prefix)
        Case insensitive check if a CharSequence starts with a specified prefix
        Parameters:
        sourceString - 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
      • endsWith

        public static boolean endsWith​(CharSequence sourceString,
                                       CharSequence suffix)
        Check if a CharSequence ends with a specified suffix
        Parameters:
        sourceString - the CharSequence to check, may be null
        suffix - the suffix to find, may be null
        Returns:
        true if the CharSequence ends with the suffix, case sensitive, or both null
      • endsWithIgnoreCase

        public static boolean endsWithIgnoreCase​(CharSequence sourceString,
                                                 CharSequence suffix)
        Case insensitive check if a CharSequence ends with a specified suffix
        Parameters:
        sourceString - the CharSequence to check, may be null
        suffix - the suffix to find, may be null
        Returns:
        true if the CharSequence ends with the suffix, case insensitive, or both null
      • normalizeSpace

        public static String normalizeSpace​(String sourceString)
        Returns the argument string with whitespace normalized
        Parameters:
        sourceString - the source String to normalize whitespaces from, may be null
        Returns:
        the modified string with whitespace normalized, null if null String input
      • appendIfMissing

        public static String appendIfMissing​(String sourceString,
                                             CharSequence suffix,
                                             CharSequence... suffixes)
        Appends the suffix to the end of the string if the string does not already end with any of the suffixes
        Parameters:
        sourceString - The string
        suffix - The suffix to append to the end of the string
        suffixes - Additional suffixes that are valid terminators
        Returns:
        A new String if suffix was appended, the same string otherwise
      • appendIfMissingIgnoreCase

        public static String appendIfMissingIgnoreCase​(String sourceString,
                                                       CharSequence suffix,
                                                       CharSequence... suffixes)
        Appends the suffix to the end of the string if the string does not already end, case insensitive, with any of the suffixes
        Parameters:
        sourceString - The string
        suffix - The suffix to append to the end of the string
        suffixes - Additional suffixes that are valid terminators
        Returns:
        A new String if suffix was appended, the same string otherwise
      • prependIfMissing

        public static String prependIfMissing​(String sourceString,
                                              CharSequence prefix,
                                              CharSequence... prefixes)
        Prepends the prefix to the start of the string if the string does not already start with any of the prefixes
        Parameters:
        sourceString - The string
        prefix - The prefix to append to the end of the string
        prefixes - Additional prefixes that are valid terminators
        Returns:
        A new String if suffix was appended, the same string otherwise
      • prependIfMissingIgnoreCase

        public static String prependIfMissingIgnoreCase​(String sourceString,
                                                        CharSequence prefix,
                                                        CharSequence... prefixes)
        Prepends the prefix to the start of the string if the string does not already start, case insensitive, with any of the prefixes
        Parameters:
        sourceString - The string
        prefix - The prefix to prepend to the start of the string
        prefixes - Additional prefixes that are valid (optional)
        Returns:
        A new String if prefix was prepended, the same string otherwise
      • wrap

        public static String wrap​(String sourceString,
                                  char wrapWith)
        Wraps a string with a char
        Parameters:
        sourceString - the string to be wrapped, may be null
        wrapWith - the char that will wrap sourceString
        Returns:
        the wrapped string, or null if sourceString==null
      • wrap

        public static String wrap​(String sourceString,
                                  String wrapWith)
        Wraps a String with another String
        Parameters:
        sourceString - the String to be wrapper, may be null
        wrapWith - the String that will wrap sourceString
        Returns:
        wrapped String, null if null String input
      • wrapIfMissing

        public static String wrapIfMissing​(String sourceString,
                                           char wrapWith)
        Wraps a string with a char if that char is missing from the start or end of the given string
        Parameters:
        sourceString - the string to be wrapped, may be null
        wrapWith - the char that will wrap sourceString
        Returns:
        the wrapped string, or null if sourceString==null
      • wrapIfMissing

        public static String wrapIfMissing​(String sourceString,
                                           String wrapWith)
        Wraps a string with a string if that string is missing from the start or end of the given string
        Parameters:
        sourceString - the string to be wrapped, may be null
        wrapWith - the char that will wrap sourceString
        Returns:
        the wrapped string, or null if sourceString==null
      • unwrap

        public static String unwrap​(String sourceString,
                                    String wrapToken)
        Unwraps a given string from anther string
        Parameters:
        sourceString - the String to be unwrapped, can be null
        wrapToken - the String used to unwrap
        Returns:
        unwrapped String or the original string if it is not quoted properly with the wrapToken
      • unwrap

        public static String unwrap​(String sourceString,
                                    char wrapChar)
        Unwraps a given string from a character
        Parameters:
        sourceString - the String to be unwrapped, can be null
        wrapChar - the character used to unwrap
        Returns:
        unwrapped String or the original string if it is not quoted properly with the wrapChar