Array in Java

Array: Array is the most important thing in any programming language. By definition, It is the static memory allocation. It allocates the memory for the same data type in sequence. It contains multiple values of same types. It also store the values in memory at the fixed size. Multiple types of arrays are used in any programming language such as: one – Dimensional, Two – Dimensional or can say Multi – Dimensional.

Declaration of an array: 
int arr[]; or int arr = new int[4];
Some times user declares an array and it’s size simultaneously. You may or may not be define the size in the declaration time. such example :
int arr[] = {40,95,75,44,88,36,26};

In this program we will see how to declare and implementation. This program illustrates that the array working way. This program takes the numbers present in the arr[] array in unordered list and prints numbers in ascending order. In this program the sort() function of the java.util.*; package is using to sort all the numbers present in the arr[] array. The Arrays.sort() automatically sorts the list of number in ascending order by default. This function held the argument which is the array name arr.

Here is the code of the program:-

import java.util.*;

public class  SimpleArray{
  public static void main(String[] args){
  int arr[] = {40,95,75,44,88,36,26};
  int l = arr.length;
  int i,j,t;
  System.out.print("Given all Number : ");
  for (i = 0;i < l;i++ ){
  System.out.print("  " + arr[i]);
  }
  System.out.println("\n");
  System.out.print("Accending order : ");
  Arrays.sort(arr);
    for(i = 0;i < l;i++){
  System.out.print("  " + arr[i]);
  }
  }
}

Output of the programme

C:\fall>javac SimpleArray.java

C:\fall>java SimpleArray
Given all Number : 40,95,75,44,88,36,26

Ascending order : 26,36,40,44,75,88,95