### Question:
CSVWriter implements Closeable, Flushable { public void writeAll (@Nonnull final List <? extends List <String>> aAllLines, final boolean bApplyQuotesToAll) { for (final List <String> aLine : aAllLines) writeNext (aLine, bApplyQuotesToAll); } CSVWriter(@Nonnull @WillCloseWhenClosed final Writer aWriter); char getSeparatorChar(); @Nonnull CSVWriter setSeparatorChar(final char cSeparator); char getQuoteChar(); @Nonnull CSVWriter setQuoteChar(final char cQuoteChar); char getEscapeChar(); @Nonnull CSVWriter setEscapeChar(final char cEscapeChar); @Nonnull @Nonempty String getLineEnd(); @Nonnull CSVWriter setLineEnd(@Nonnull @Nonempty final String sLineEnd); boolean isAvoidFinalLineEnd(); @Nonnull CSVWriter setAvoidFinalLineEnd(final boolean bAvoidFinalLineEnd); boolean isApplyQuotesToAll(); @Nonnull CSVWriter setApplyQuotesToAll(final boolean bApplyQuotesToAll); void writeAll(@Nonnull final List <? extends List <String>> aAllLines, final boolean bApplyQuotesToAll); void writeAll(@Nonnull final List <? extends List <String>> aAllLines); void writeNext(@Nullable final Iterator <String> aNextLine, final boolean bApplyQuotesToAll); void writeNext(@Nullable final Iterable <String> aNextLine, final boolean bApplyQuotesToAll); void writeNext(@Nullable final Iterable <String> aNextLine); void writeNext(@Nullable final String [] aNextLine, final boolean bApplyQuotesToAll); void writeNext(@Nullable final String... aNextLine); void writeNext(@Nullable final String [] aNextLine,
                         @Nonnegative final int nOfs,
                         @Nonnegative final int nLength,
                         final boolean bApplyQuotesToAll); void writeNext(@Nullable final String [] aNextLine, @Nonnegative final int nOfs, @Nonnegative final int nLength); void flush(); void close(); boolean checkError(); @Nonnegative int getWrittenLines(); void flushQuietly(); static final char NO_QUOTE_CHARACTER; static final char NO_ESCAPE_CHARACTER; static final String DEFAULT_LINE_END; static final boolean DEFAULT_QUOTE_ALL; static final boolean DEFAULT_AVOID_FINAL_LINE_END; }### Answer:
@Test public void testWriteAll () throws IOException { final ICommonsList <ICommonsList <String>> allElements = new CommonsArrayList <> (); allElements.add (StringHelper.getExploded ('#', "Name#Phone#Email")); allElements.add (StringHelper.getExploded ('#', "Glen#1234#glen@abcd.com")); allElements.add (StringHelper.getExploded ('#', "John#5678#john@efgh.com")); final NonBlockingStringWriter aSW = new NonBlockingStringWriter (); try (final CSVWriter aWriter = new CSVWriter (aSW)) { aWriter.writeAll (allElements); } final String sResult = aSW.getAsString ().trim (); final String [] aLines = StringHelper.getExplodedArray ('\n', sResult); assertEquals (3, aLines.length); }
@Test public void testWriteAllObjects () throws IOException { final ICommonsList <ICommonsList <String>> allElements = new CommonsArrayList <> (); allElements.add (StringHelper.getExploded ('#', "Name#Phone#Email")); allElements.add (StringHelper.getExploded ('#', "Glen#1234#glen@abcd.com")); allElements.add (StringHelper.getExploded ('#', "John#5678#john@efgh.com")); final NonBlockingStringWriter aSW = new NonBlockingStringWriter (); try (final CSVWriter aWriter = new CSVWriter (aSW)) { aWriter.writeAll (allElements, false); } final String sResult = aSW.getAsString (); final String [] aLines = StringHelper.getExplodedArray ('\n', sResult.trim ()); assertEquals (3, aLines.length); final String [] aValues = StringHelper.getExplodedArray (',', aLines[1]); assertEquals (3, aValues.length); assertEquals ("1234", aValues[1]); }