I want to prepend a String to a variable list of String arguments.
public String myMethod(String... args) {
return myOtherMethod("some string" + args);
}
Now, this of course will not work, because you cannot add these two types as such. How can I insert this string at the beginning of the list and then call myOtherMethod()?
EDIT: myOtherMethod() takes another String... as its argument. I am also limited to Java 7.
There isn't a way around creating a new
String[], like so:Or, if third-party libraries are allowed, using Guava you could just write