Created
October 11, 2011 04:18
-
-
Save dtulig/1277255 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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