RSS Feed for This PostCurrent Article

Java VarArgs - An Overlooked Feature

I think VarArgs feature available since JDK1.5 is often overlooked by developer. It is handly when you want to pass multiple arguments of the same types to a function.

E.g.


public class TestArgs {

    public void print(String... text){
        for (String val:text){
            System.out.println(val);
        }
    }

    public static void main(String args[]){
        TestArgs arg = new TestArgs();
        arg.print("testing");
        arg.print("testing", "testing");
        arg.print("testing", "testing", "testing");

    }
}


Trackback URL


RSS Feed for This PostPost a Comment