Module MaterialFX

Class StringUtils

java.lang.Object
io.github.palexdev.materialfx.utils.StringUtils

public class StringUtils extends Object
Utils class for Strings.
  • Field Details

  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • difference

      public static String difference(String str1, String str2)
      Finds the difference between two Strings.
      Parameters:
      str1 - The first String
      str2 - The second String
      Returns:
      the difference between the two given strings
    • indexOfDifference

      public static int indexOfDifference(CharSequence cs1, CharSequence cs2)
      Finds the index at which two CharSequences differ.
      Parameters:
      cs1 - The first sequence
      cs2 - The second sequence
    • replaceLast

      public static String replaceLast(String string, String substring, String replacement)
      Replaces the last occurrence of the given string with a new string.
      Parameters:
      string - The string to modify
      substring - The last occurrence to find
      replacement - The replacement
      Returns:
      The modified string
    • replaceIndex

      public static String replaceIndex(String string, int startIndex, int endIndex, String replacement)
    • titleCaseWord

      public static String titleCaseWord(String str)
    • containsIgnoreCase

      public static boolean containsIgnoreCase(CharSequence str, CharSequence searchStr)

      Checks if a CharSequence contains a search CharSequence irrespective of case, handling null. Case-insensitivity is defined as by String.equalsIgnoreCase(String).

      A null CharSequence will return false.

    • startsWithIgnoreCase

      public static boolean startsWithIgnoreCase(String str, String prefix)
      Checks if thee given string starts with the specifies prefix, ignores case.
    • endsWithIgnoreCase

      public static boolean endsWithIgnoreCase(String str, String suffix)
      Checks if the given string ends with the given prefix, ignores case.
    • containsAny

      public static boolean containsAny(String str, String split, String... words)
      Checks if the given string contains at least one of the given words.
      Parameters:
      split - this is the character that will split the input string, see String.split(String)
    • containsAll

      public static boolean containsAll(String str, String split, String... words)
      Checks if the given string contains all the specifies words.
      Parameters:
      split - this is the character that will split the input string, see String.split(String)
    • timeToHumanReadable

      public static String timeToHumanReadable(long elapsedSeconds)
      A useful method to convert a given elapsed time in seconds to a String.

      - "Just now" if elapsed is less than 60 seconds

      - minutes + " minutes ago" if the elapsed seconds is greater than 60 seconds

      - hours + " minutes ago" if the elapsed minutes are greater than 60 minutes

      - days + " days ago" if the elapsed hours are greater than 24

    • randAlphabetic

      public static String randAlphabetic(int length)
      Generates a random alphabetic string of given length
    • randAlphanumeric

      public static String randAlphanumeric(int length)
      Generates a random alphanumeric string of given length