com.blackperl.Perl
Class Join

java.lang.Object
  |
  +--com.blackperl.Perl.Join

public final class Join
extends java.lang.Object

Static-method implementation of the Perl join keyword. This class makes available as static methods various forms of the join functionality. All forms accomplish the same thing: they return a String object that is the concatenation of the list of strings, using the token as a separator in between. The variations are only to permit flexibility in how the separator is specified.

For example, if the array stringArray contained the strings: "one", "two", "three" and "four", then the following:

     import com.blackperl.Perl.Join;
 
     String joined = Join.join(" and a ", stringArray);
 

Would yield the string:

     one and a two and a three and a four
 

Since the sequence used for joining is often a single character, there is a form that allows the first argument to be of type char. If the same array were used for this:

     import com.blackperl.Perl.Join;
 
     String joined = Join.join(',', stringArray);
 

The result would be:

     one,two,three,four
 

If the array passed to join is empty or null, then an empty (zero-length) string value is returned.

All components in this package provide an instance method to retrieve a singleton object which may be used to call the static methods, if the programmer prefers using an object to static invocation.

If this is the JDK 1.5 ("Tiger") edition of the package, this class is suitable for use via static import:

     import com.blackperl.Perl.Join.join;
 
     String joined = join(',', stringArray);
     // Same result as the previous example
 


Method Summary
static com.blackperl.Perl.Join instance()
          The instance method is used to retrieve the Join singleton that applications can use in lieu of invoking the methods statically.
static java.lang.String join(char token, java.lang.String[] array)
          Create a String by concatenating the items in the array together, with an instance of the separator between each.
static java.lang.String join(java.lang.String token, java.lang.String[] array)
          Create a String by concatenating the items in the array together, with an instance of the separator between each.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static com.blackperl.Perl.Join instance()
The instance method is used to retrieve the Join singleton that applications can use in lieu of invoking the methods statically.

Returns:
Singleton instance of the Chomp class

join

public static java.lang.String join(char token,
                                    java.lang.String[] array)
Create a String by concatenating the items in the array together, with an instance of the separator between each.

Parameters:
token - A single character to use as the separator
array - Array of String objects to join together
Returns:
The crafted String

join

public static java.lang.String join(java.lang.String token,
                                    java.lang.String[] array)
Create a String by concatenating the items in the array together, with an instance of the separator between each.

Parameters:
token - The String to use as the separator
array - Array of String objects to join together
Returns:
The crafted String