Class StringHelper

java.lang.Object
io.github.torand.javacommons.lang.StringHelper

public final class StringHelper extends Object
Provides general purpose string utilities.
  • Method Details

    • nonBlank

      public static boolean nonBlank(String string)
      Tests whether the specified string is not null and contains at least one character.
      Parameters:
      string - the string to test.
      Returns:
      true if the string is not null and contains at least one character; else false.
    • isBlank

      public static boolean isBlank(String string)
      Tests whether the specified string is null or contains no characters.
      Parameters:
      string - the string to test.
      Returns:
      true if the string is null or contains no characters; else false.
    • generate

      public static String generate(String string, int count)
      Creates a string by concatenating a substring multiple times.
      Parameters:
      string - the substring.
      count - the number of repetitions.
      Returns:
      the generated string.
    • generate

      public static String generate(String string, int count, String delimiter)
      Creates a string by concatenating a substring multiple times delimited by a delimiter substring.
      Parameters:
      string - the substring.
      count - the number of repetitions.
      delimiter - the delimiter.
      Returns:
      the generated string.
    • quote

      public static String quote(String string)
      Returns the specified string enclosed by double quotes.
      Parameters:
      string - the string.
      Returns:
      the quoted string.
    • quoteIfString

      public static Object quoteIfString(Object object)
      If the specified object is a string, returns it enclosed by double quotes.
      Parameters:
      object - the object, which might be a string.
      Returns:
      the quoted string or unmodified object.
    • quoteAll

      public static List<String> quoteAll(List<String> strings)
      Returns specified list with all strings quoted.
      Parameters:
      strings - the list.
      Returns:
      the list of quoted strings.
    • stripHead

      public static String stripHead(String string, int count)
      Removes a specific number of leading characters from a string.
      Parameters:
      string - the string.
      count - the number of characters to remove.
      Returns:
      the stripped string.
    • stripTail

      public static String stripTail(String string, int count)
      Removes a specific number of trailing characters from a string.
      Parameters:
      string - the string.
      count - the number of characters to remove.
      Returns:
      the stripped string.
    • capitalize

      public static String capitalize(String string)
      Returns specified string with upper case first letter.
      Parameters:
      string - the string.
      Returns:
      the capitalized string.
    • uncapitalize

      public static String uncapitalize(String string)
      Returns specified string with lower case first letter.
      Parameters:
      string - the string.
      Returns:
      the uncapitalized string.