public final class Join extends Object
Appendable or just return a String. For example,
join(":", "a", "b", "c") returns "a:b:c".
All 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 by the string "null".
| Modifier and Type | Class and Description |
|---|---|
static class |
Join.JoinException
Exception thrown in response to an
IOException from the supplied
Appendable. |
| Modifier and Type | Method and Description |
|---|---|
static String |
join(String delimiter,
Iterable<?> tokens)
Returns a string containing the
tokens, converted to strings if
necessary, separated by delimiter. |
static String |
join(String delimiter,
Iterator<?> tokens)
Returns a string containing the
tokens, converted to strings if
necessary, separated by delimiter. |
static String |
join(String delimiter,
Object[] tokens)
Returns a string containing the
tokens, converted to strings if
necessary, separated by delimiter. |
static String |
join(String delimiter,
Object firstToken,
Object... otherTokens)
Returns a string containing the
tokens, converted to strings if
necessary, separated by delimiter. |
static String |
join(String keyValueSeparator,
String entryDelimiter,
Map<?,?> map)
Returns a string containing the contents of
map, with entries
separated by entryDelimiter, and keys and values separated with
keyValueSeparator. |
static <T extends Appendable> |
join(T appendable,
String delimiter,
Iterable<?> tokens)
Appends each of the
tokens to appendable, separated by
delimiter. |
static <T extends Appendable> |
join(T appendable,
String delimiter,
Iterator<?> tokens)
Appends each of the
tokens to appendable, separated by
delimiter. |
static <T extends Appendable> |
join(T appendable,
String delimiter,
Object[] tokens)
Appends each of the
tokens to appendable, separated by
delimiter. |
static <T extends Appendable> |
join(T appendable,
String delimiter,
Object firstToken,
Object... otherTokens)
Appends each of the
tokens to appendable, separated by
delimiter. |
static <T extends Appendable> |
join(T appendable,
String keyValueSeparator,
String entryDelimiter,
Map<?,?> map)
Appends the contents of
map to appendable, with entries
separated by entryDelimiter, and keys and values separated with
keyValueSeparator. |
public static String join(String delimiter, Iterable<?> tokens)
tokens, converted to strings if
necessary, separated by delimiter. If tokens is empty, it
returns an empty string.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
delimiter - a string to append between every element, but not at the
beginning or endtokens - objects to appendpublic static String join(String delimiter, Object[] tokens)
tokens, converted to strings if
necessary, separated by delimiter. If tokens is empty, it
returns an empty string.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
delimiter - a string to append between every element, but not at the
beginning or endtokens - objects to appendpublic static String join(String delimiter, @Nullable Object firstToken, Object... otherTokens)
tokens, converted to strings if
necessary, separated by delimiter.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
delimiter - a string to append between every element, but not at the
beginning or endfirstToken - the first object to appendotherTokens - subsequent objects to appendpublic static String join(String delimiter, Iterator<?> tokens)
tokens, converted to strings if
necessary, separated by delimiter. If tokens is empty, it
returns an empty string.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
delimiter - a string to append between every element, but not at the
beginning or endtokens - objects to appendpublic static String join(String keyValueSeparator, String entryDelimiter, Map<?,?> map)
map, with entries
separated by entryDelimiter, and keys and values separated with
keyValueSeparator.
Each key and value will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
keyValueSeparator - a string to append between every key and its
associated valueentryDelimiter - a string to append between every entry, but not at
the beginning or endmap - the map containing the data to joinpublic static <T extends Appendable> T join(T appendable, String delimiter, Iterable<?> tokens)
tokens to appendable, separated by
delimiter.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
appendable - the object to append the results todelimiter - a string to append between every element, but not at the
beginning or endtokens - objects to appendAppendable instance that was passed inJoin.JoinException - if an IOException occurspublic static <T extends Appendable> T join(T appendable, String delimiter, Object[] tokens)
tokens to appendable, separated by
delimiter.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
appendable - the object to append the results todelimiter - a string to append between every element, but not at the
beginning or endtokens - objects to appendAppendable instance that was passed inJoin.JoinException - if an IOException occurspublic static <T extends Appendable> T join(T appendable, String delimiter, @Nullable Object firstToken, Object... otherTokens)
tokens to appendable, separated by
delimiter.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
appendable - the object to append the results todelimiter - a string to append between every element, but not at the
beginning or endfirstToken - the first object to appendotherTokens - subsequent objects to appendAppendable instance that was passed inJoin.JoinException - if an IOException occurspublic static <T extends Appendable> T join(T appendable, String delimiter, Iterator<?> tokens)
tokens to appendable, separated by
delimiter.
Each token will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
appendable - the object to append the results todelimiter - a string to append between every element, but not at the
beginning or endtokens - objects to appendAppendable instance that was passed inJoin.JoinException - if an IOException occurspublic static <T extends Appendable> T join(T appendable, String keyValueSeparator, String entryDelimiter, Map<?,?> map)
map to appendable, with entries
separated by entryDelimiter, and keys and values separated with
keyValueSeparator.
Each key and value will be converted to a CharSequence using
String.valueOf(Object), if it isn't a CharSequence already.
Note that this implies that null tokens will be appended as the
four-character string "null".
appendable - the object to append the results tokeyValueSeparator - a string to append between every key and its
associated valueentryDelimiter - a string to append between every entry, but not at
the beginning or endmap - the map containing the data to joinAppendable instance that was passed inCopyright © 2009–2016. All rights reserved.