com.su.utils
Class StrU

java.lang.Object
  extended by com.su.utils.StrU

public class StrU
extends Object

The String Utilities (StrU) help you to manipulate Strings, Lists and Arrays easier. It does no error checking, so NPEs are possible. This allows the user to be able to handle errors exactly as they want.
The methods should be access like StrU.methodName(args).

Since:
1.0
Version:
1.0
Author:
cstoss

Constructor Summary
StrU()
           
 
Method Summary
static String concat(Object... args)
          This creates a String from a series of Object arguments using the Object.toString() method.
static String concat(String... args)
          This is a convenience method.
static String delim(char[] charArray)
          Create a delimited String from an array of chars
static String delim(char[] charArray, String delim)
          Create a delimited String from an array of chars
static String delim(double[] doubleArray)
          Create a delimited String from an array of doubles
static String delim(double[] doubleArray, String delim)
          Create a delimited String from an array of doubles
static String delim(float[] floatArray)
          Create a delimited String from an array of floats
static String delim(float[] floatArray, String delim)
          Create a delimited String from an array of floats
static String delim(int[] intArray)
          Create a delimited String from an array of ints
static String delim(int[] intArray, String delim)
          Create a delimited String from an array of ints
static String delim(List list)
          Create a comma delimited String from a List of Objects
static String delim(List list, String delim)
          Create a delimited String from a List of Objects
static String delim(Object[] objArray)
          Create a comma delimited String from an array of Objects
static String delim(Object[] objArray, String delim)
          Create a delimited String from an array of Objects
static void pr(Object... args)
          This will print out the Objects(s) that you specify to System.out using the concat(Object...) method.
static List<String> splitIntoList(String s, String delim)
          Splits String s into a List Object using the delimiter delim
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StrU

public StrU()
Method Detail

splitIntoList

public static List<String> splitIntoList(String s,
                                         String delim)
Splits String s into a List Object using the delimiter delim

Parameters:
s - the String to split
delim - the delimiter to split the String on
Returns:
a List of Strings based on the split
See Also:
String.split(String)

delim

public static String delim(List list,
                           String delim)
Create a delimited String from a List of Objects

Parameters:
list - the list of Objects;
delim - the delimiter to place between Objects;
Returns:
a String of the Objects separated by delim using the Object.toString() method.

delim

public static String delim(List list)
Create a comma delimited String from a List of Objects

Parameters:
list - the list of Objects;
Returns:
a String of the Objects separated by ',' using the Object.toString() method.

delim

public static String delim(Object[] objArray)
Create a comma delimited String from an array of Objects

Parameters:
objArray - the array to delimit
Returns:
a String of the Objects separated by ',' using the Object.toString() method.

delim

public static String delim(Object[] objArray,
                           String delim)
Create a delimited String from an array of Objects

Parameters:
objArray - the array to delimit
delim - the delimiter
Returns:
a String of the Objects separated by delim using the Object.toString() method.

delim

public static String delim(int[] intArray)
Create a delimited String from an array of ints

Parameters:
intArray - the array to delimit
Returns:
a String of the ints separated by ','.

delim

public static String delim(int[] intArray,
                           String delim)
Create a delimited String from an array of ints

Parameters:
intArray - the array to delimit
delim - the delimiter
Returns:
a String of the ints separated by delim.

delim

public static String delim(double[] doubleArray)
Create a delimited String from an array of doubles

Parameters:
doubleArray - the array to delimit
Returns:
a String of the doubles separated by ','.

delim

public static String delim(double[] doubleArray,
                           String delim)
Create a delimited String from an array of doubles

Parameters:
doubleArray - the array to delimit
delim - the delimiter
Returns:
a String of the doubles separated by delim.

delim

public static String delim(float[] floatArray)
Create a delimited String from an array of floats

Parameters:
floatArray - the array to delimit
Returns:
a String of the floats separated by ','.

delim

public static String delim(float[] floatArray,
                           String delim)
Create a delimited String from an array of floats

Parameters:
floatArray - the array to delimit
delim - the delimiter
Returns:
a String of the floats separated by delim.

delim

public static String delim(char[] charArray)
Create a delimited String from an array of chars

Parameters:
charArray - the array to delimit
Returns:
a String of the chars separated by ','.

delim

public static String delim(char[] charArray,
                           String delim)
Create a delimited String from an array of chars

Parameters:
charArray - the array to delimit
delim - the delimiter
Returns:
a String of the chars separated by delim.

concat

public static String concat(Object... args)
This creates a String from a series of Object arguments using the Object.toString() method.
In many cases using 'String str += "" + Object' and other combinations can be non-performant, because of the underlying implementation of the + operator on Objects and Strings.
This implementation uses a StringBuffer and takes in a variable amount of arguments and returns the concatenation in an easy way instead of using the methods above.
Sample usage:
     System.out.println(StringUtils.concat("MyStr equals ", myStr, " and yourStr equals ", yourStr));

This is also a simple replacement for the MessageFormat method.

You can write a method:
                String finalScoreMessage(int mine, in yours){
                        return StringUtils.concat("The final score is ", mine, " to ", yours, ".");
                }
 

This would then allow you to use consistent message throughout your program without the overhead of MessageFormat.

Parameters:
args - The Objects you wish to concatenate.
Returns:
The concatenation of the Objects using the toString() method.
See Also:
StringBuffer.append(String)

concat

public static String concat(String... args)
This is a convenience method. It is identical to concat(Object...) except that it will only activate when all arguments are already Strings. This makes it slightly more performant as it avoids the toString() method on Objects.

Parameters:
args - String to concatenate
Returns:
all the Strings concatenated
See Also:
concat(Object...)

pr

public static void pr(Object... args)
This will print out the Objects(s) that you specify to System.out using the concat(Object...) method.

Parameters:
args - the Objects to print.
See Also:
concat(Object...)