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.Since: 2.0 (imported from Google Collections Library)Author: Kevin BourrillionNested Class SummaryNested Classes Modifier and TypeClass and Descriptionstatic class Joiner.MapJoinerAn object that joins map entries in the same manner as Joiner joins iterables and arrays.Method SummaryMethods Modifier and TypeMethod and Description
AappendTo(A appendable, Iterable parts)Appends the string representation of each of parts, using the previously configured separator between each, to appendable.
AappendTo(A appendable, Iterator parts)Appends the string representation of each of parts, using the previously configured separator between each, to appendable.
AappendTo(A appendable, Object[] parts)Appends the string representation of each of parts, using the previously configured separator between each, to appendable.
AappendTo(A appendable, Object first, Object second, Object... rest)Appends to appendable the string representation of each of the remaining arguments.StringBuilderappendTo(StringBuilder builder, Iterable parts)Appends the string representation of each of parts, using the previously configured separator between each, to builder.StringBuilderappendTo(StringBuilder builder, Iterator parts)Appends the string representation of each of parts, using the previously configured separator between each, to builder.StringBuilderappendTo(StringBuilder builder, Object[] parts)Appends the string representation of each of parts, using the previously configured separator between each, to builder.StringBuilderappendTo(StringBuilder builder, Object first, Object second, Object... rest)Appends to builder the string representation of each of the remaining arguments.Stringjoin(Iterable parts)Returns a string containing the string representation of each of parts, using the previously configured separator between each.Stringjoin(Iterator parts)Returns a string containing the string representation of each of parts, using the previously configured separator between each.Stringjoin(Object[] parts)Returns a string containing the string representation of each of parts, using the previously configured separator between each.Stringjoin(Object first, Object second, Object... rest)Returns a string containing the string representation of each argument, using the previously configured separator between each.static Joineron(char separator)Returns a joiner which automatically places separator between consecutive elements.static Joineron(String separator)Returns a joiner which automatically places separator between consecutive elements.JoinerskipNulls()Returns a joiner with the same behavior as this joiner, except automatically skipping over any provided null elements.JoineruseForNull(String nullText)Returns a joiner with the same behavior as this one, except automatically substituting nullText for any provided null elements.Joiner.MapJoinerwithKeyValueSeparator(String keyValueSeparator)Returns a MapJoiner using the given key-value separator, and the same configuration as this Joiner otherwise.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethod Detailonpublic static Joiner on(String separator)Returns a joiner which automatically places separator between consecutive elements.onpublic static Joiner on(char separator)Returns a joiner which automatically places separator between consecutive elements.appendTopublic A appendTo(A appendable, Iterable parts) throws IOExceptionAppends the string representation of each of parts, using the previously configured separator between each, to appendable.Throws:IOExceptionappendTopublic A appendTo(A appendable, Iterator parts) throws IOExceptionAppends the string representation of each of parts, using the previously configured separator between each, to appendable.Throws:IOExceptionSince: 11.0appendTopublic final A appendTo(A appendable, Object[] parts) throws IOExceptionAppends the string representation of each of parts, using the previously configured separator between each, to appendable.Throws:IOExceptionappendTopublic final A appendTo(A appendable, @Nullable Object first, @Nullable Object second, Object... rest) throws IOExceptionAppends to appendable the string representation of each of the remaining arguments.Throws:IOExceptionappendTopublic final StringBuilder appendTo(StringBuilder builder, Iterable parts)Appends the string representation of each of parts, using the previously configured separator between each, to builder. Identical to appendTo(Appendable, Iterable), except that it does not throw IOException.appendTopublic final StringBuilder appendTo(StringBuilder builder, Iterator parts)Appends the string representation of each of parts, using the previously configured separator between each, to builder. Identical to appendTo(Appendable, Iterable), except that it does not throw IOException.Since: 11.0appendTopublic final StringBuilder appendTo(StringBuilder builder, Object[] parts)Appends the string representation of each of parts, using the previously configured separator between each, to builder. Identical to appendTo(Appendable, Iterable), except that it does not throw IOException.appendTopublic final StringBuilder appendTo(StringBuilder builder, @Nullable Object first, @Nullable Object second, Object... rest)Appends to builder the string representation of each of the remaining arguments. Identical to appendTo(Appendable, Object, Object, Object...), except that it does not throw IOException.joinpublic final String join(Iterable parts)Returns a string containing the string representation of each of parts, using the previously configured separator between each.joinpublic final String join(Iterator parts)Returns a string containing the string representation of each of parts, using the previously configured separator between each.Since: 11.0joinpublic final String join(Object[] parts)Returns a string containing the string representation of each of parts, using the previously configured separator between each.joinpublic final String join(@Nullable Object first, @Nullable Object second, Object... rest)Returns a string containing the string representation of each argument, using the previously configured separator between each.useForNull@CheckReturnValuepublic Joiner useForNull(String nullText)Returns a joiner with the same behavior as this one, except automatically substituting nullText for any provided null elements.skipNulls@CheckReturnValuepublic Joiner skipNulls()Returns a joiner with the same behavior as this joiner, except automatically skipping over any provided null elements.withKeyValueSeparator@CheckReturnValuepublic Joiner.MapJoiner withKeyValueSeparator(String keyValueSeparator)Returns a MapJoiner using the given key-value separator, and the same configuration as this Joiner otherwise.