Java: How to pass array to another function

Sometimes we may need in java programming to pass the value of array in another function.

Here I have given an example about the procedure of passing an array to a function.

Also, here I have shown how to find out the length of an array and how to retrieve or get the value of the array after passing it to another function.

This tutorial will help you to understand the basic of array and how to declare array in java.

Code:

 class ArrayPassing

{

 public static void checking(String[] u)

  {

 System.out.println(“\n”);

System.out.println(“****************************************”);

  System.out.println(“Array is entered into Checking function”);

  System.out.println(“Array Length:”+u.length);

  System.out.println(“Third index value is:”+u[2]);

  System.out.println(“\n”);

  System.out.println(“****************************************”);

  }

         public static void main(String args[])

                        {

                                    String[] d;

                                    d = new String[3];

                                    d[0]=”1″;

                                    d[1]=”2″;

                                    d[2]=”5″;

                                     checking(d);

                                     }

}

OUTPUT:

About these ads

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

Join 296 other followers

%d bloggers like this: