Iterable, varargs or even a
Map) with a separator. It either appends the results to an Appendable or returns
them as a String. Example:
Joiner joiner = Joiner.on("; ").skipNulls();
. . .
return joiner.join("Harry", null, "Ron", "Hermione");
This returns the string "Harry; Ron; Hermione". Note that all input elements are
converted to strings using Object#toString() before being appended.
If neither skipNulls() nor useForNull(String) is specified, the joining
methods will throw NullPointerException if any given element is null.
Warning: joiner instances are always immutable; a configuration method such as useForNull has no effect on the instance it is invoked on! You must store and use the new joiner
instance returned by the method. This makes joiners thread-safe, and safe to store as static final constants.
// Bad! Do not do this!
Joiner joiner = Joiner.on(',');
joiner.skipNulls(); // does nothing!
return joiner.join("wrong", null, "wrong");
See the Guava User Guide article on Joiner.
| Modifier and Type | Class and Description |
|---|---|
| public static class | Joiner.MapJoiner
An object that joins map entries in the same manner as |
| Access | Constructor and Description |
|---|---|
| private | |
| private |
| Modifier and Type | Method and Description |
|---|---|
| public <A extends Appendable> A | |
| public <A extends Appendable> A | |
| public final <A extends Appendable> A | |
| public final <A extends Appendable> A | |
| public final StringBuilder | appendTo(StringBuilder builder, Iterable<? extends @Nullable Object> parts)
Appends the string representation of each of |
| public final StringBuilder | appendTo(StringBuilder builder, Iterator<? extends @Nullable Object> parts)
Appends the string representation of each of |
| public final StringBuilder | appendTo(StringBuilder builder, @Nullable Object[] parts)
Appends the string representation of each of |
| public final StringBuilder | |
| private static Iterable | |
| public final String | |
| public final String | |
| public final String | |
| public final String | |
| public static Joiner | |
| public static Joiner | on(char separator)
Returns a joiner which automatically places |
| public Joiner | skipNulls()
Returns a joiner with the same behavior as this joiner, except automatically skipping over any provided null elements. |
| pack-priv CharSequence | |
| public Joiner | useForNull(String nullText)
Returns a joiner with the same behavior as this one, except automatically substituting |
| public Joiner. | withKeyValueSeparator(char keyValueSeparator)
Returns a |
| public Joiner. | withKeyValueSeparator(String keyValueSeparator)
Returns a |
| separator | back to summary |
|---|---|
| private final String separator | |
| Joiner | back to summary |
|---|---|
| private Joiner(String separator) | |
| Joiner | back to summary |
|---|---|
| private Joiner(Joiner prototype) | |
| appendTo | back to summary |
|---|---|
| public <A extends Appendable> A appendTo(A appendable, Iterable<? extends @Nullable Object> parts) throws IOException Appends the string representation of each of
| |
| appendTo | back to summary |
|---|---|
| public <A extends Appendable> A appendTo(A appendable, Iterator<? extends @Nullable Object> parts) throws IOException Appends the string representation of each of
| |
| appendTo | back to summary |
|---|---|
| public final <A extends Appendable> A appendTo(A appendable, @Nullable Object[] parts) throws IOException Appends the string representation of each of
| |
| appendTo | back to summary |
|---|---|
| public final <A extends Appendable> A appendTo(A appendable, Object first, Object second, @Nullable Object... rest) throws IOException Appends to
| |
| appendTo | back to summary |
|---|---|
| public final StringBuilder appendTo(StringBuilder builder, Iterable<? extends @Nullable Object> parts) Appends the string representation of each of
| |
| appendTo | back to summary |
|---|---|
| public final StringBuilder appendTo(StringBuilder builder, Iterator<? extends @Nullable Object> parts) Appends the string representation of each of
| |
| appendTo | back to summary |
|---|---|
| public final StringBuilder appendTo(StringBuilder builder, @Nullable Object[] parts) Appends the string representation of each of
| |
| appendTo | back to summary |
|---|---|
| public final StringBuilder appendTo(StringBuilder builder, Object first, Object second, @Nullable Object... rest) Appends to
| |
| iterable | back to summary |
|---|---|
| private static Iterable | |
| join | back to summary |
|---|---|
| public final String join(Iterable<? extends @Nullable Object> parts) Returns a string containing the string representation of each of | |
| join | back to summary |
|---|---|
| public final String join(Iterator<? extends @Nullable Object> parts) Returns a string containing the string representation of each of
| |
| join | back to summary |
|---|---|
| public final String join(@Nullable Object[] parts) Returns a string containing the string representation of each of | |
| join | back to summary |
|---|---|
| public final String join(Object first, Object second, @Nullable Object... rest) Returns a string containing the string representation of each argument, using the previously configured separator between each. | |
| on | back to summary |
|---|---|
| public static Joiner on(String separator) Returns a joiner which automatically places | |
| on | back to summary |
|---|---|
| public static Joiner on(char separator) Returns a joiner which automatically places | |
| skipNulls | back to summary |
|---|---|
| public Joiner skipNulls() Returns a joiner with the same behavior as this joiner, except automatically skipping over any provided null elements. | |
| toString | back to summary |
|---|---|
| pack-priv CharSequence toString(Object part) | |
| useForNull | back to summary |
|---|---|
| public Joiner useForNull(String nullText) Returns a joiner with the same behavior as this one, except automatically substituting | |
| withKeyValueSeparator | back to summary |
|---|---|
| public Joiner. Returns a
| |
| withKeyValueSeparator | back to summary |
|---|---|
| public Joiner. Returns a | |
Joiner joins iterables and
arrays. Like Joiner, it is thread-safe and immutable.
In addition to operating on Map instances, MapJoiner can operate on Multimap entries in two distinct modes:
multimap.entries() to a
MapJoiner method that accepts entries as input, and receive output of the form
key1=A&key1=B&key2=C.
multimap.asMap() to a MapJoiner method that accepts a map as input, and receive output of the form key1=[A, B]&key2=C.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public <A extends Appendable> A | |
| public StringBuilder | appendTo(StringBuilder builder, Map<?, ?> map)
Appends the string representation of each entry of |
| public <A extends Appendable> A | |
| public <A extends Appendable> A | |
| public StringBuilder | appendTo(StringBuilder builder, Iterable<? extends Map.
Appends the string representation of each entry in |
| public StringBuilder | appendTo(StringBuilder builder, Iterator<? extends Map.
Appends the string representation of each entry in |
| public String | |
| public String | |
| public String | |
| public Joiner. | useForNull(String nullText)
Returns a map joiner with the same behavior as this one, except automatically substituting
|
| joiner | back to summary |
|---|---|
| private final Joiner joiner | |
| keyValueSeparator | back to summary |
|---|---|
| private final String keyValueSeparator | |
| MapJoiner | back to summary |
|---|---|
| private MapJoiner(Joiner joiner, String keyValueSeparator) | |
| appendTo | back to summary |
|---|---|
| public <A extends Appendable> A appendTo(A appendable, Map<?, ?> map) throws IOException Appends the string representation of each entry of
| |
| appendTo | back to summary |
|---|---|
| public StringBuilder appendTo(StringBuilder builder, Map<?, ?> map) Appends the string representation of each entry of
| |
| appendTo | back to summary |
|---|---|
| public <A extends Appendable> A appendTo(A appendable, Iterable<? extends Map. Appends the string representation of each entry in
| |
| appendTo | back to summary |
|---|---|
| public <A extends Appendable> A appendTo(A appendable, Iterator<? extends Map. Appends the string representation of each entry in
| |
| appendTo | back to summary |
|---|---|
| public StringBuilder appendTo(StringBuilder builder, Iterable<? extends Map. Appends the string representation of each entry in
| |
| appendTo | back to summary |
|---|---|
| public StringBuilder appendTo(StringBuilder builder, Iterator<? extends Map. Appends the string representation of each entry in
| |
| join | back to summary |
|---|---|
| public String join(Map<?, ?> map) Returns a string containing the string representation of each entry of | |
| join | back to summary |
|---|---|
| public String join(Iterable<? extends Map. Returns a string containing the string representation of each entry in
| |
| join | back to summary |
|---|---|
| public String join(Iterator<? extends Map. Returns a string containing the string representation of each entry in
| |
| useForNull | back to summary |
|---|---|
| public Joiner. Returns a map joiner with the same behavior as this one, except automatically substituting
| |