Java - Array in Java

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.print("Accending order number : ");
  for(i = 0;i < l;i++){
  System.out.print("  " + num[i]);

Output of the program:


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

Ascending order number : 20 25 45 50 63 82


Share on Google+Share on Google+

Java - Array in Java

Posted on: June 5, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: Java - Array in Java   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
March 8, 2013
advance programming

Chetan pote
August 21, 2012

very nice but my question
September 14, 2012

where use int i in pgm and 1=num.length
Bishnu Sharma
September 23, 2012

Fabulous example to understand numeric array in java.
October 12, 2012
java Array in descending order

PLease help me how to create a program that well give in Array in descending order.. even i gave an input a mix number
October 16, 2012
array demo of library system

can you give me some sample of program for library system.
June 16, 2013
write a program that print the prime number

i am very thankful if you give correct solution
June 25, 2013

write a program to accept 'n' no of String inputs using array concept.
January 15, 2014
parts of Java Array

please answer my question. What are the parts of java array?? ASAP.. Thank you