Package org.fest.util

Class Strings

java.lang.Object
org.fest.util.Strings

public final class Strings extends Object
Understands utility methods related to Strings.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Understands how to join Strings using a given delimiter.
    static class 
    Understands how to append a given String to the given target, only if the target does not end with the given String to append.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    append(String toAppend)
    Appends a given String to the given target, only if the target does not end with the given String to append.
    static String
    concat(Object... objects)
    Concatenates the given objects into a single String.
    static boolean
    Returns true if the given String is null or empty.
    join(String... strings)
    Joins the given Strings using a given delimiter.
    static Object
    Returns the given object surrounded by single quotes, only if the object is a String.
    static String
    Returns the given String surrounded by single quotes, or null if the given String is null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Strings

      private Strings()
  • Method Details

    • isEmpty

      public static boolean isEmpty(String s)
      Returns true if the given String is null or empty.
      Parameters:
      s - the String to check.
      Returns:
      true if the given String is null or empty, otherwise false.
    • quote

      public static String quote(String s)
      Returns the given String surrounded by single quotes, or null if the given String is null.
      Parameters:
      s - the given String.
      Returns:
      the given String surrounded by single quotes, or null if the given String is null.
    • quote

      public static Object quote(Object o)
      Returns the given object surrounded by single quotes, only if the object is a String.
      Parameters:
      o - the given object.
      Returns:
      the given object surrounded by single quotes, only if the object is a String.
      See Also:
    • concat

      public static String concat(Object... objects)
      Concatenates the given objects into a single String. This method is more efficient than concatenating using "+", since only one StringBuilder is created.
      Parameters:
      objects - the objects to concatenate.
      Returns:
      a String containing the given objects.
    • join

      public static Strings.StringsToJoin join(String... strings)
      Joins the given Strings using a given delimiter. The following example illustrates proper usage of this method:
       Strings.join("a", "b", "c").with("|")
       
      which will result in the String "a|b|c".
      Parameters:
      strings - the Strings to join.
      Returns:
      an intermediate object that takes a given delimiter and understands how to join the given Strings.
      See Also:
    • append

      public static Strings.StringToAppend append(String toAppend)
      Appends a given String to the given target, only if the target does not end with the given String to append. The following example illustrates proper usage of this method:
       Strings.append("c").to("ab");
       Strings.append("c").to("abc");
       
      which will result in the String "abc" for both cases.
      Parameters:
      toAppend - the String to append.
      Returns:
      an intermediate object that takes the target String and knows to append the given String.
      See Also: