Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Created June 19, 2013 12:01
Show Gist options
  • Save kentcdodds/5813751 to your computer and use it in GitHub Desktop.
Save kentcdodds/5813751 to your computer and use it in GitHub Desktop.
Utility methods for Java I don't want to think about ever again...
/**
* Simulates javascript's .join function.
*/
public static String combine(String glue, String... stringsToCombine) {
int arryLength = stringsToCombine.length;
if (arryLength == 0) {
return null;
}
StringBuilder out = new StringBuilder();
out.append(stringsToCombine[0]);
for (int x=1; x < arryLength; ++x) {
out.append(glue).append(stringsToCombine[x]);
}
return out.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment