Question: Let's say I have two overloaded methods, `void foo(int arg)` and `void foo(int[] args)`. Both do the same processing on the integer parameters. Now, I've implemented them in this way

```
void foo(int arg){
    // Some processing.
}

void foo(int[] args){
    for(int i : args)
        //The same processing as above.
}

```

Now, I know it is a better design principle to avoid code duplication, so the second method can also be implemented as :

```
void foo(int[] args){
    for(int i : args)
        foo(i);
}

```

However, since I am calling the method inside several times, and since method calls add overheads, this approach would make it slower. So, my question is : Which approach should I use?

Answer: 
You are talking about a really insignificant overhead. I have a little program that will help you understand how insignificant it is:

```
class Bar {
    void foo(double d) {        
        double y = (d + 1) * d / 7.1 % 31.3 + 13.12 * 20.002;
    }

    void foo1(double[] args) {
        for (double d : args) {
            foo(d);
        }
    }

    void foo2(double[] args) {
        for (double d : args) {
            double y = (d + 1) * d / 7.1 % 31.3 + 13.12 * 20.002;
        }
    }
}

```

Here is a test and sample run 

```
   public class Main {
        public static void test(int n) {
            System.out.print(n + ",");

            double is[] = new double[n];
            for (int i = 0; i < is.length; i++) {
                is[i] = i * 1.3;
            }

            Bar bar = new Bar();
            long span;

            long start = System.currentTimeMillis();
            bar.foo1(is);
            span = System.currentTimeMillis() - start;
            System.out.print(span + ",");

            start = System.currentTimeMillis();
            bar.foo2(is);
            span = System.currentTimeMillis() - start;
            System.out.print(span + "\n");
        }

        public static void main(String[] args) {
            test(10000000);
            test(20000000);
            test(30000000);
            test(40000000);
            test(50000000);
            test(60000000);
        }
    }

```

And here is the a output:

```
10000000,389,383
20000000,743,766
30000000,1130,1113
40000000,1497,1474
50000000,1866,1853
60000000,2243,2239

```

More complex the foo method is, more insignificant the difference will be. So IMHO forget about the performance, think about maintainability.
Get rid of the first one altogether, and change the second one to:

```
void foo(int...args)

```

with the same code body. Then you won't have either repetition or an extra method call, just the loop-control overhead, which isn't going to kill you.