Home Java Beginners Java - Array in Java



Java - Array in Java
Posted on: June 5, 2007 at 12:00 AM
Array is the most important thing in any programming language.

Array Example - Array in Java

     

Array: Array is the most important thing in any programming language. By definition, array 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 num[]; or int num = new int[2];
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 as:
int num[] = {50,20,45,82,25,63}; 

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 num[] 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 num[] 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 num.

Here is the code of the program:-

import java.util.*;

public class  array{
 
 public static void main(String[] args){
  int num[] = {50,20,45,82,25,63};
  int l = num.length;
  int i,j,t;
  System.out.print("Given number : ");
  for (i = 0;i < l;i++ ){
  System.out.print("  " + num[i]);
  }
  System.out.println(
"\n");
  System.out.print("Accending order number : ");
  Arrays.sort(num);
  
  for(i = 0;i < l;i++){
  System.out.print("  " + num[i]);
  }
  }
}

Output of the program:

C:\chandan>javac array.java

C:\chandan>java array
Given number : 50 20 45 82 25 63

Ascending order number : 20 25 45 50 63 82

  

Related Tags for Java - Array in Java:
javacarraysarraylistfunctionfuniosortprintimplementationdefaultnumbersordernumbernameusingintthispackagecalluncworkprogramtoautomaticramicalldargumentautoeilliulimcefaultinnocalasmnttrcajpackclesdeclareworkingemfuncendautomaticallyallagemehowprorateratesackunowhichssoeeatpackishallomamplprerayandascendingarstrrtrtsutilunorderedvautiscessrirdthavstatihatefaulteclendingicaicapleplprndonomogronor


More Tutorials from this section

Ask Questions?    Discuss: Java - Array in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.