Search This Blog

Tuesday, 3 January 2012

Power of ... in Java

you can pass the any number of paramters when u specified(...). Normally it holds the data in array format.  Consider the below examples.
class ParameterExample
{
    public static void main(String... ag) //it same as String[] ag
    {
        String ary[]=ag;
        System.out.println(ary.length);
    }
}







class ParameterExample
{
    public static void main(String... ag) //it same as String[] ag
    {
        stringDisplay("H","A","I");
    }
    static void stringDisplay(String...a) //it get the data as Array Format
    {
        for(String o:a)
        System.out.print(o);
    }
   
}

No comments:

Post a Comment