Class StringUtil


  • public class StringUtil
    extends Object
    Static helper methods dealing with Strings and CharSequences.
    Author:
    Torsten.Hildebrandt
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • repeat

        public static String repeat​(CharSequence toRepeat,
                                    int n)
        Repeats a given String/CharSequence a certain number of times.
        Parameters:
        toRepeat - The CharSequence (usually a String) to repeat. Mustn't be null.
        n - How many times to repeat it. If n is 0 or negative, an empty String will be returned.
        Returns:
        A String containing n copies of toRepeat.
      • isNullOrEmpty

        public static boolean isNullOrEmpty​(CharSequence cs)
        Return true is the given parameter (usually a String) is either null or empty.
        Parameters:
        cs - The CharSequence to check.
        Returns:
        true, is the parameter was null or had a length of 0; false otherwise.
      • replaceLineBreaks

        public static String replaceLineBreaks​(String s)
        Replace all line breaks in the given String by " \n " to make it print in a single line.
      • equals

        public static boolean equals​(String s1,
                                     String s2)
        Returns true if both strings are either null or s1.equal(s2).