Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Beginners Java - Array in Java

 
 

Share on Google+Share on Google+

Java - Array in Java

Advertisement
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

  

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 5, 2007

Related Tutorials

Discuss: Java - Array in Java   View All Comments

Post your Comment


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

nice
Chetan pote
August 21, 2012
java

very nice but my question
veerappan
September 14, 2012
hi

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

Fabulous example to understand numeric array in java.
Berserker
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
jess
October 16, 2012
array demo of library system

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

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

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

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