Variable length argument implemented using array.


This Example demonstrates how we can pass variable argument using array, but this approach is old. Now a days we use Varargs feature included in J2SE 5.

class VariableArr{
public void Test(int[] arr)

{ System.out.println("No. of args "+arr.length+"contents ");

for(int i : arr)

{ System.out.print( i+" ");

}

System.out.println();

}

public static void main(String a[])

{ VariableArr va= nw VariableArr();

int a[]= {20};

int b[]={2,4,6};

int c[]= {};

va.test(a);

va.test(b);

va.test(c);

}

}

, ,

  1. #1 by ultrasound technician at June 14th, 2010

    I’ve recently started a blog, the information you provide on this site has helped me tremendously. Thank you for all of your time & work.

  2. #2 by CNA Practice Test at June 21st, 2010

    Keep up the good work, I like your writing.

(will not be published)
  1. No trackbacks yet.