title: How to pass variables as arguments only if it is not null in Java
body: <p>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.</p>
  
  <pre><code>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) {
  
  }
  </code></pre>
  
  <p>In the above code snippet. I want to call testMethod() with arguments arg1, arg2, arg4 only because arg3 is NULL.</p>
  
  <p>The number of arguments may vary. It will not be 4 all the time.</p>
  
  <p>My code should dynamically check if an argument is not NULL and pass it to the testMethod().</p>
  
  <p>Can I achieve this in Java. If Yes, can someone help me ..</p>