Last active
May 11, 2016 11:05
-
-
Save hofiorg/be6e9447321d1157a5ae17e7e12725cf to your computer and use it in GitHub Desktop.
Java - Variable Arguments
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
public class Varargs2 { | |
public static String insertComma(String... values) { | |
String result = ""; | |
boolean first = true; | |
for (String value : values) { | |
result += (first ? "" : ", ") + value; | |
first = false; | |
} | |
return result; | |
} | |
public static void main(String[] args) { | |
System.out.println(insertComma("hallo")); | |
System.out.println(insertComma("hallo", "welt")); | |
System.out.println(insertComma("hallo", "welt", "123")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment