Class StringUtil

java.lang.Object
eu.cloudnetservice.utils.base.StringUtil

public final class StringUtil extends Object
Utility class for working with strings.
Since:
4.0
  • Field Details

    • SECURE_RANDOM

      private static final Random SECURE_RANDOM
    • DEFAULT_ALPHABET_UPPERCASE

      private static final char[] DEFAULT_ALPHABET_UPPERCASE
  • Constructor Details

    • StringUtil

      private StringUtil()
  • Method Details

    • generateRandomString

      @NonNull public static @NonNull String generateRandomString(int length)
      Generates a random string consisting of uppercase characters and digits with the provided length.
      Parameters:
      length - the length the generated string should have.
      Returns:
      the randomly generated string.
      Throws:
      IllegalArgumentException - if the given string length is zero or negative.
    • endsWithIgnoreCase

      public static boolean endsWithIgnoreCase(@NonNull @NonNull String string, @NonNull @NonNull String suffix)
      Checks if the given string ends with the given suffix ignoring the string casing.
      Parameters:
      string - the string to check for the given suffix.
      suffix - the suffix to validate the string ends with.
      Returns:
      true if the given string ends with the given suffix, false otherwise.
      Throws:
      NullPointerException - if the given string or suffix is null.
    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(@NonNull @NonNull String string, @NonNull @NonNull String prefix)
      Checks if the given string starts with the given prefix ignoring the string casing.
      Parameters:
      string - the string to check for the given prefix.
      prefix - the prefix to validate the string starts with.
      Returns:
      true if the given string starts with the given prefix, false otherwise.
      Throws:
      NullPointerException - if the given string or prefix is null.
    • toLower

      @Contract("!null -> !null; null -> null") @Nullable public static @Nullable String toLower(@Nullable @Nullable String string)
      Converts all the characters in the given string to lower case using a locale insensitive operation. This method returns null in case the given string is null.
      Parameters:
      string - the string to convert to lowercase, can be null.
      Returns:
      the same string as given with all characters converted to lower case.
    • toUpper

      @Contract("!null -> !null; null -> null") @Nullable public static @Nullable String toUpper(@Nullable @Nullable String string)
      Converts all the characters in the given string to upper case using a locale insensitive operation.This method returns null in case the given string is null.
      Parameters:
      string - the string to convert, to uppercase, can be null.
      Returns:
      the same string as given with all characters converted to upper case.
    • repeat

      @NonNull public static @NonNull String repeat(char c, int times)
      Repeats the given character the given amount times and returns a string consisting of the reputation result.
      Parameters:
      c - the character to repeat.
      times - the amount of times to repeat the character.
      Returns:
      a string consisting of the given amount of times of the given char.
      Throws:
      IllegalArgumentException - if the given time to repeat the char is negative.