Only the last Parameter is allowed to be variable Length:
String prepareStatement(String[] columnNames, String... values)
String... is equal to String[] so in this case you could insert a String[] for the first parameter and just check if its empty or how long it is.
Edit to your Edit
If you really need an input for all your Strings as Parameters I would recommend to define a really really uncommon String to seperate your inputs:
static String prepareStatement(String... params)
{
String ret = "";
boolean valueInput = false;
for(String s : params)
{
if(s.equals("MyReallyUncommonSeperateString"))
{
valueInput = true;
ret+="\nvalues\n";//visual delimiter of columnNames and Values
}
else if(valueInput)
{
//handling of your value inputs
ret+=s; //example handling, concatenate everything
}
else
{
//handling of your columnnames
ret+=s; //example handling, concatenate everything
}
}
return ret;
}
You can call it:
System.out.println(prepareStatement("a","b","c","d","e","MyReallyUncommonSeperateString","f","g","h","i","j","k"));
Output:
abcde
values
fghijk
Another way is to give the length of the columnNames as parameter as well:
static String prepareStatement(int length, String... params)
{
String ret = "";
for(int i = 0; i < length; i++){
//handling of columnnames
String colName = params[i];
//do something with colName
ret+=colName; //example handling, concatenate everything
}
ret+="\nvalues\n";//visual delimiter of columnNames ans Values
for(int i = length; i < params.length; i++){
String value = params[i];
//do something with values
ret+=value; //example handling, concatenate everything
}
return ret;
}
With the call:
System.out.println(prepareStatement(5, "a","b","c","d","e","f","g","h","i","j","k"));
And the same output:
abcde
values
fghijk