So they're all thread-safe. Their constructors are private, and their static methods must be called to generate their objects (without reflecting the constructed object case)
public class Chapter2code {private final list<string> List = lists.newarraylist ("name", "Doctor", "Sex", "man", null ); @Rulepublic expectedexception expectedexception = Expectedexception.none (); @Testpublic void Test_joiner () {Joiner Jo Iner = Joiner.on (","). Skipnulls (); Assertthat (Joiner.join (list), Equalto ("Name,doctor,sex,man")); Joiner = Joiner.on (","). Usefornull ("null"); Assertthat (Joiner.join (list), Equalto ("Name,doctor,sex,man,null")); Joiner = Joiner.on ("|"); Expectedexception.expect (Nullpointerexception.class);//If NULL pointers are not processed, an exception is thrown. Joiner.join (list);} @Testpublic void Test_joiner_wrong_use () {Joiner Joiner = Joiner.on (","); Joiner.skipnulls ();//This method generates a new object that has no effect on the settings of the original object Expectedexception.expect (Nullpointerexception.class); Joiner.join (list);} @Testpublic void Test_joiner_appendto_stringbuilder () {Joiner Joiner = Joiner.on ("|"). Skipnulls (); StringBuilder builder = new StringBuilder (256); Joiner.appendto (builder, list); Assertthat (BUIlder.tostring (), Equalto ("Name|doctor|sex|man")); System.out.println (Builder.tostring ());} @Testpublic void Test_joiner_appendto_file () throws IOException {File File = new file ("A.txt"); if (!file.exists ()) {file.createnewfile (); } try (FileWriter FileWriter = new FileWriter (file);) {Joiner.on ("#"). Skipnulls (). AppendTo (FileWriter, list); } catch (Exception e) {throw new RuntimeException (e); } list<string> lines = Files.readalllines (Paths.get ("a.txt")); SYSTEM.OUT.PRINTLN (lines); Assertthat (Joiner.on (""). Join (lines), Equalto (Joiner.on ("#"). Skipnulls (). Join (list));} @Testpublic void Test_mapjoiner () {map<string, string> Map = Maps.newlinkedhashmap (); Map.put ("Name", "Doctor"); Map.put ("Sex", "man"); String join = Joiner.on (","). Withkeyvalueseparator ("="). Join (map); Assertthat (Join, Equalto ("Name=doctor,sex=man"));}}