Class Joiner
- java.lang.Object
-
- org.glassfish.jersey.internal.guava.Joiner
-
public class Joiner extends Object
An object which joins pieces of text (specified as an array,Iterable, varargs or even aMap) with a separator. It either appends the results to anAppendableor returns them as aString. Example:<p> 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 usingObject.toString()before being appended.If neither
#skipNulls()nor#useForNull(String)is specified, the joining methods will throwNullPointerExceptionif any given element is null.Warning: joiner instances are always immutable; a configuration method such as
useForNullhas 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 asstatic finalconstants.<p> // 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 Bourrillion
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJoiner.MapJoinerAn object that joins map entries in the same manner asJoinerjoins iterables and arrays.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Joineron()Returns a joiner which automatically placesseparatorbetween consecutive elements.Joiner.MapJoinerwithKeyValueSeparator()Returns aMapJoinerusing the given key-value separator, and the same configuration as thisJoinerotherwise.
-
-
-
Method Detail
-
on
public static Joiner on()
Returns a joiner which automatically placesseparatorbetween consecutive elements.
-
withKeyValueSeparator
public Joiner.MapJoiner withKeyValueSeparator()
Returns aMapJoinerusing the given key-value separator, and the same configuration as thisJoinerotherwise.
-
-