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+" ");




public static void main(String a[])

{ VariableArr va= nw VariableArr();

int a[]= {20};

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

int c[]= {};






2 thoughts on “Variable length argument implemented using array.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s