public class Joiner extends Object
If neither skipNulls() nor useForNull(String) is specified, the joining methods will throw IllegalArgumentException if any given element is null.
| Modifier and Type | Field and Description |
|---|---|
static Joiner |
PATH_JOINER
Ready to use Joiner for paths
|
| Modifier and Type | Method and Description |
|---|---|
<A extends Appendable> |
appendIterableTo(A appendable,
Iterable<?> parts)
Appends parts of
Iterable to a given Appendable |
<A extends Appendable> |
appendTo(A appendable,
Object... parts)
Appends parts to a given
Appendable. |
String |
join(Object... parts)
Joins parts and returns them as a string.
|
String |
joinIterable(Iterable<?> parts)
Joins parts and returns them as a string.
|
Joiner |
noDuplicateSeparators()
Configures Joiner to prevent duplicate separators.
|
static Joiner |
on(String separator)
Creates a new Joiner object with a specified separator.
|
Joiner |
skipNulls()
Configures Joiner to ignore
null elements. |
Joiner |
useForNulls(String forNulls)
Sets the string to use in place of
null elements. |
public static final Joiner PATH_JOINER
public static Joiner on(String separator)
null values in input
and will put separators even if they are already presentseparator - Separator to use for text concatenation.public Joiner useForNulls(String forNulls)
null elements. If Joiner is set to skip nulls this method does
nothing.forNulls - String to substitute nulls with.public Joiner skipNulls()
null elements. If useForNulls(String) has been configured, it will
be ignored from now on.public Joiner noDuplicateSeparators()
For example
Joiner.on("/").join("/", "somepath", "otherpath/", "/filename");
will return "//somepath/otherpath///filename" and
Joiner.on("/").noDuplicateSeparators().join("/", "somepath", "otherpath/", "/filename");
will return "/somepath/otherpath/filename"
public String join(Object... parts)
Object.toString() is called on each part before joining.parts - Parts of string to be joined.IllegalArgumentException - if parts contain null and neither skipNulls() nor
useForNulls(String) are used.public String joinIterable(Iterable<?> parts)
Object.toString() is called on each part before joining.parts - Parts of string to be joined.IllegalArgumentException - if parts contain null and neither skipNulls() nor
useForNulls(String) are used.public <A extends Appendable> void appendTo(A appendable, Object... parts) throws IOException
Appendable. Object.toString() is called on each part before joining.A - Type of Appendableappendable - Appendable to append parts toparts - Parts to be joinedIOException - Thrown by AppendableIllegalArgumentException - if parts contain null and neither skipNulls() nor
useForNulls(String) are used.public <A extends Appendable> void appendIterableTo(A appendable, Iterable<?> parts) throws IOException
Iterable to a given AppendableA - Type of Appendableappendable - Appendable to append parts toparts - Iterable of partsIOException - Thrown by AppendableIllegalArgumentException - if parts contain null and neither skipNulls() nor
useForNulls(String) are used.Copyright © 2018. All rights reserved.