Created
June 19, 2013 12:01
-
-
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...
This file contains 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
/** | |
* 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