Algernon Software

org.algernon.util
Class StringUtil

java.lang.Object
  extended byorg.algernon.util.StringUtil

public class StringUtil
extends Object

Contains various useful string utilities.


Constructor Summary
StringUtil()
           
 
Method Summary
static String arrayToString(Object[] arr)
          Converts an array into a printable string.
static String collectionToString(Collection col)
          Converts a collection of String into a single comma-delimited string
static String collectionToString(Collection col, String delimiter)
           
static String concatenateStrings(Collection strings, String separator)
          Converts the objects in a Collection into strings and concatenates them, with an separator string between the interior divisions.
static boolean isEmpty(String str)
          Returns true if the string is null or empty.
static String leftJustify(String s, int width)
          Returns a new string with spaces on the right to make the string as wide as the given width.
static String makeString(int length)
          Creates a blank string of the given length containing the given character (default blank).
static String makeString(int length, char fill)
          Creates a string of the given length containing the given character (default blank).
static String rightJustify(String s, int width)
          Returns a new string with spaces on the left to make the string as wide as the given width.
static Collection stringSplit(String string, String separator)
          Splits a string into a collection of strings.
static String[] stringToArray(String string, String delimiter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

isEmpty

public static boolean isEmpty(String str)
Returns true if the string is null or empty.


stringSplit

public static Collection stringSplit(String string,
                                     String separator)
Splits a string into a collection of strings. Provide the initial string and a delimiter. Will not strip whitespace characters unless specified.


stringToArray

public static String[] stringToArray(String string,
                                     String delimiter)

arrayToString

public static String arrayToString(Object[] arr)
Converts an array into a printable string.


collectionToString

public static String collectionToString(Collection col)
Converts a collection of String into a single comma-delimited string

Parameters:
col - the collection of String

collectionToString

public static String collectionToString(Collection col,
                                        String delimiter)

rightJustify

public static String rightJustify(String s,
                                  int width)
Returns a new string with spaces on the left to make the string as wide as the given width. If the string length is already greater than or equal to the given width, the string is returned unchanged.


leftJustify

public static String leftJustify(String s,
                                 int width)
Returns a new string with spaces on the right to make the string as wide as the given width. If the string length is already greater than or equal to the given width, the string is returned unchanged.


concatenateStrings

public static String concatenateStrings(Collection strings,
                                        String separator)
Converts the objects in a Collection into strings and concatenates them, with an separator string between the interior divisions.

Parameters:
strings -
Returns:
a String containing the concatenation of the input strings.

makeString

public static String makeString(int length)
Creates a blank string of the given length containing the given character (default blank).

Parameters:
length - the length of the string. Must be 0 or greater.

makeString

public static String makeString(int length,
                                char fill)
Creates a string of the given length containing the given character (default blank).

Parameters:
length - the length of the string. Must be 0 or greater.

Algernon Software