I have the following code stub where I'm reading a set of values from properties file. I need to use these values to pass it as arguments to a function only if they aren't NULL.
public static void main(String[] args) {
String arg1 = "arg1";
String arg2 = "arg2";
String arg3 = null;
String arg4 = "arg4";
.
.
.
testMethod(arg1, arg2, arg3);
}
public void testMethod(String... values) {
}
In the above code snippet. I want to call testMethod() with arguments arg1, arg2, arg4 only because arg3 is NULL.
The number of arguments may vary. It will not be 4 all the time.
My code should dynamically check if an argument is not NULL and pass it to the testMethod().
Can I achieve this in Java. If Yes, can someone help me ..
testMethod(String... values)method by passing an array of all your variables, and in that method you kind of manually check if the variables arenulland which other method you want to call.