Menu

Title

Subtitle

Advantage of Java Array
⦁    Code Optimization: It makes the code optimized, we can retrieve or sort the data easily.
⦁    Random access: We can get any data located at any index position.

Disadvantage of Java Array
⦁    Size Limit: We can store only fixed size of elements in the array. It doesn't grow its size at runtime. To solve this problem, collection framework is used in java.
Types of Array in java
There are two types of array.
⦁    Single Dimensional Array
⦁    Multidimensional Array

Single Dimensional Array in java
Syntax to Declare an Array in java
⦁    dataType[] arr; (or) 
⦁    dataType []arr; (or) 
⦁    dataType arr[]; 
Instantiation of an Array in java
⦁    arrayRefVar=new datatype[size]; 
Example of single dimensional java array
Let's see the simple example of java array, where we are going to declare, instantiate, initialize and traverse an array.
⦁    class Testarray{ 
⦁    public static void main(String args[]){ 
⦁     
⦁    int a[]=new int[5];//declaration and instantiation 
⦁    a[0]=10;//initialization 
⦁    a[1]=20; 
⦁    a[2]=70; 
⦁    a[3]=40; 
⦁    a[4]=50; 
⦁     
⦁    //printing array 
⦁    for(int i=0;i<a.length;i++)//length is the property of array 
⦁    System.out.println(a[i]); 
⦁     
⦁    }} 
Test it Now
Output: 10
       20
       70
       40
       50
      

Declaration, Instantiation and Initialization of Java Array
We can declare, instantiate and initialize the java array together by:
⦁    int a[]={33,3,4,5};//declaration, instantiation and initialization 
Let's see the simple example to print this array.
⦁    class Testarray1{ 
⦁    public static void main(String args[]){ 
⦁     
⦁    int a[]={33,3,4,5};//declaration, instantiation and initialization 
⦁     
⦁    //printing array 
⦁    for(int i=0;i<a.length;i++)//length is the property of array 
⦁    System.out.println(a[i]); 
⦁     
⦁    }} 
Test it Now
Output:33
       3
       4
       5
   

Passing Array to method in java
We can pass the java array to method so that we can reuse the same logic on any array.
Let's see the simple example to get minimum number of an array using method.
⦁    class Testarray2{ 
⦁    static void min(int arr[]){ 
⦁    int min=arr[0]; 
⦁    for(int i=1;i<arr.length;i++) 
⦁     if(min>arr[i]) 
⦁      min=arr[i]; 
⦁     
⦁    System.out.println(min); 
⦁    } 

click here know more extratorrent.cc

 

Welcome To Your Website

Customizing your website is easy. Just login and point your mouse at any content block on the page and an editor will appear allowing you to edit, move or delete.  Click on the text and start typing.

To add more content, change your theme, or access other features, explore the toolbar at the top of the page.

You can move your components by dragging and dropping on a different area of the page.

Content

You can change this Page Layout in the toolbar above if you want to have a different content layout on this page.

You can add more content to this page by clicking the 'Add Content to Page' button.