Class StringUtilities

Object
StringUtilities

public class StringUtilities extends Object
Utility functions for manipualting strings.
Author:
Owen Feehan
  • Method Details

    • joinNonEmpty

      public static Optional<String> joinNonEmpty(String delimeter, String... stringMaybeEmpty)
      Like String.join(java.lang.CharSequence, java.lang.CharSequence...) but ignores any empty strings, and returns Optional.empty() if all components are empty.
      Parameters:
      delimeter - delimeter to use when joining strings
      stringMaybeEmpty - strings that may or may not be empty.
      Returns:
      a joined string including only the non-empty strings, and with a delimeter between them.
    • leftPad

      public static String leftPad(String string, int targetLength)
      Left-pad a string with whitespace, so it reaches a fixed length.
      Parameters:
      string - the string without padding.
      targetLength - the desired total length of string, for which padding may be added.
      Returns:
      a string, is either padded with whitespace to give a length targetLength unless it is already larger than targetLength.
    • rightPad

      public static String rightPad(String string, int targetLength)
      Right-pad a string with whitespace, so it reaches a fixed length.
      Parameters:
      string - the string without padding.
      targetLength - the desired total length of string, for which padding may be added.
      Returns:
      a string, is either padded with whitespace to give a length targetLength unless it is already larger than targetLength.