Class StringUtil


  • public class StringUtil
    extends Object
    Useful String-related utilities.
    • Constructor Detail

      • StringUtil

        public StringUtil()
    • Method Detail

      • s

        public static String s​(int n)
      • ies

        public static String ies​(int n)
      • classNameWithoutQualifiers

        public static String classNameWithoutQualifiers​(String className)
      • classNameWithoutPackageQualifiers

        public static String classNameWithoutPackageQualifiers​(String className)
      • repeat

        public static String repeat​(char c,
                                    int n)
      • split

        public static String split​(String s,
                                   int n)
        Line-wraps s by inserting a newline instead of the first space after the nth column. Word-wraps.
      • capitalize

        public static String capitalize​(String word)
      • uncapitalize

        public static String uncapitalize​(String word)
      • fromCommaDelimitedString

        public static List fromCommaDelimitedString​(String s)
        Converts the comma-delimited string into a List of trimmed strings.
        Parameters:
        s - a String with comma-delimited values
        Returns:
        a List of the Strings that were delimited by commas
      • blankStringList

        public static List blankStringList​(int size)
        Returns a List of empty Strings.
        Parameters:
        size - the size of the List to create
        Returns:
        a List of blank Strings
      • toFriendlyName

        public static String toFriendlyName​(String className)
      • friendlyName

        public static String friendlyName​(Class c)
      • toFriendlyName

        public static String toFriendlyName​(String className,
                                            String substringToRemove)
      • insertSpaces

        public static String insertSpaces​(String s)
      • toCommaDelimitedString

        public static String toCommaDelimitedString​(Collection c)
        Returns the elements of c separated by commas. If c is empty, an empty String will be returned.
        Parameters:
        c - a Collection of objects to convert to Strings and delimit by commas
        Returns:
        a String containing c's elements, delimited by commas
      • replaceAll

        public static String replaceAll​(String original,
                                        String oldSubstring,
                                        String newSubstring)
        Returns original with all occurrences of oldSubstring replaced by newSubstring
      • replace

        public static String replace​(String original,
                                     String oldSubstring,
                                     String newSubstring,
                                     boolean all)
        Returns original with occurrences of oldSubstring replaced by newSubstring. Set all to true to replace all occurrences, or false to replace the first occurrence only.
      • replace

        public static void replace​(StringBuffer orig,
                                   String o,
                                   String n,
                                   boolean all)
        Replaces all instances of the String o with the String n in the StringBuffer orig if all is true, or only the first instance if all is false. Posted by Steve Chapel on UseNet
      • stackTrace

        public static String stackTrace​(Throwable t)
        Returns an throwable's stack trace
      • head

        public static String head​(String s,
                                  int lines)
      • limitLength

        public static String limitLength​(String s,
                                         int maxLength)
      • isNumber

        public static boolean isNumber​(String token)
      • toTimeString

        public static String toTimeString​(long milliseconds)