|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.common.base.Join
public final class Join
Join is the only utility for joining pieces of text separated by a delimiter that you will ever need. It can handle Iterators, Collections, arrays, and varargs, and can append to any Appendable or just return a String.
A trivial example: join(":", "a", "b", "c")
gives "a:b:c". See JoinTest for more examples.
All the methods of this class throw NullPointerException when a
value of null is supplied for any parameter. The elements within
the collection, iterator, array, or varargs parameter list may be
null -- these will be represented in the output with the string
"null".
| Nested Class Summary | |
|---|---|
static class |
Join.JoinException
Thrown in response to an IOException from the supplied
Appendable. |
| Method Summary | ||
|---|---|---|
static java.lang.String |
join(java.lang.String delimiter,
java.lang.Iterable<?> tokens)
Returns a String containing the tokens, converted to Strings if
necessary, separated by delimiter. |
|
static java.lang.String |
join(java.lang.String delimiter,
java.util.Iterator<?> tokens)
Variant of join(String,Iterable) where tokens is an
Iterator. |
|
static java.lang.String |
join(java.lang.String delimiter,
java.lang.Object[] tokens)
Variant of join(String,Iterable) where tokens is an
array. |
|
static java.lang.String |
join(java.lang.String delimiter,
java.lang.Object firstToken,
java.lang.Object... otherTokens)
Variant of join(String,Iterable) for tokens given using varargs. |
|
static
|
join(T appendable,
java.lang.String delimiter,
java.lang.Iterable<?> tokens)
Variant of join(Appendable,String,Iterator) where tokens
is an Iterable. |
|
static
|
join(T appendable,
java.lang.String delimiter,
java.util.Iterator<?> tokens)
Appends each of the tokens to appendable, separated by
delimiter. |
|
static
|
join(T appendable,
java.lang.String delimiter,
java.lang.Object[] tokens)
Variant of join(Appendable,String,Iterator) where tokens
is an array. |
|
static
|
join(T appendable,
java.lang.String delimiter,
java.lang.Object firstToken,
java.lang.Object... otherTokens)
Variant of join(Appendable,String,Iterator) for tokens given using
varargs. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static <T extends java.lang.Appendable> T join(T appendable,
java.lang.String delimiter,
java.util.Iterator<?> tokens)
tokens to appendable, separated by
delimiter.
appendable - the non-null object to append the results todelimiter - a non-null String to append between every element, but not
at the beginning or endtokens - Objects of any type. For each element, if it is an instance
of CharSequence it will be appended as-is, otherwise it
will be converted to a CharSequence using
String.valueOf(Object). Note that this implies that null
tokens will be appended as the four-character string
"null".
Join.JoinException - if an IOException occurs
public static java.lang.String join(java.lang.String delimiter,
java.lang.Iterable<?> tokens)
tokens, converted to Strings if
necessary, separated by delimiter. If tokens is empty,
returns the empty string.
public static <T extends java.lang.Appendable> T join(T appendable,
java.lang.String delimiter,
java.lang.Iterable<?> tokens)
join(Appendable,String,Iterator) where tokens
is an Iterable.
public static <T extends java.lang.Appendable> T join(T appendable,
java.lang.String delimiter,
java.lang.Object[] tokens)
join(Appendable,String,Iterator) where tokens
is an array.
public static <T extends java.lang.Appendable> T join(T appendable,
java.lang.String delimiter,
@Nullable
java.lang.Object firstToken,
java.lang.Object... otherTokens)
join(Appendable,String,Iterator) for tokens given using
varargs.
public static java.lang.String join(java.lang.String delimiter,
java.util.Iterator<?> tokens)
join(String,Iterable) where tokens is an
Iterator.
public static java.lang.String join(java.lang.String delimiter,
java.lang.Object[] tokens)
join(String,Iterable) where tokens is an
array.
public static java.lang.String join(java.lang.String delimiter,
@Nullable
java.lang.Object firstToken,
java.lang.Object... otherTokens)
join(String,Iterable) for tokens given using varargs.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||