Skip to content

Instantly share code, notes, and snippets.

@dtulig
Created October 11, 2011 04:18
Show Gist options
  • Save dtulig/1277255 to your computer and use it in GitHub Desktop.
Save dtulig/1277255 to your computer and use it in GitHub Desktop.
final Joiner joiner = Joiner.on(",")
.skipNulls();
StringBuilder builder = new StringBuilder();
final String[] input1 = new String[] {"dave", "john"};
builder = joiner.appendTo(builder, input1);
// Dave and John have a comma between them.
final String[] input2 = new String[]{null, "dan"};
builder = joiner.appendTo(builder, input2);
// The string is now "dave,johndan".
final String[] input3 = new String[]{"matt", "sam"};
final String result = joiner.appendTo(builder, input3).toString();
// And finally we will have "dave, johndanmatt,sam".
// result = dave,johndanmatt,sam
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment