varArgs Example to calculate sum of numbers (calling same method independent of number of input parameters)
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4215698/java-how-can-i-create-a-function-that-supports-any-number-of-parameters">java: how can i create a function that supports any number of parameters?</a>  </p>
</blockquote>



<p>Is there a way to call a generic function from other functions irrespective of the input parameters ?
If my input data types are all same (either int only or String only)</p>

<pre><code>public class sumOfNo {

public static void main(String[] arg) {

    /**
     * Normal way of calling function to calculate sum.
     */
     int result = sum(1, 2);
     int result1 = sum(1, 2, 3);
</code></pre>

<p>}</p>

<pre><code>/**
 * A normal function overloading method of calculating sum
 * @return
 */

 private static int sum(int i, int i0) {
     int c = i + i0;
     System.out.println("c:" + c);
     return c;
 }

 private static int sum(int i, int i0, int i1) {
     int c = i + i0 + i1;
     System.out.println("c:" + c);
     return c;
 }

}
</code></pre>
