java - Concatenate variable argument list -
i want prepend string variable list of string arguments.
public string mymethod(string... args) { return myothermethod("some string" + args); } now, of course not work, because cannot add these 2 types such. how can insert string @ beginning of list , call myothermethod()?
edit: myothermethod() takes string... argument. limited java 7.
there isn't way around creating new string[], so:
public string mymethod(string... args) { string[] concatenatedarray = new string[args.length + 1]; concatenatedarray[0] = "other string"; (int = 0; < args.length; i++) { // or system.arraycopy... concatenatedarray[i + 1] = args[i]; } return myothermethod(concatenatedarray); } or, if third-party libraries allowed, using guava write
return myothermethod(objectarrays.concat("other string", args));
Comments
Post a Comment