0% found this document useful (0 votes)
247 views

Array in Java

An array in Java allows storing multiple data items of the same type in contiguous memory blocks divided into slots. There are three types of arrays: single dimensional arrays which store data in a single list, two dimensional arrays which store data in a grid of rows and columns, and multidimensional arrays which combine these. A sample program declares a single dimensional integer array of size 100, initializes it with a for loop, and prints the elements.

Uploaded by

Nina Canares
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
247 views

Array in Java

An array in Java allows storing multiple data items of the same type in contiguous memory blocks divided into slots. There are three types of arrays: single dimensional arrays which store data in a single list, two dimensional arrays which store data in a grid of rows and columns, and multidimensional arrays which combine these. A sample program declares a single dimensional integer array of size 100, initializes it with a for loop, and prints the elements.

Uploaded by

Nina Canares
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Array in Java
In Java and other programming languages, there is one
capability wherein we can use one variable to store a list of
data and manipulate them more efficiently. This type of variable
is called an array.

An array stores multiple data items of the same data type,


in a contiguous block of memory, divided into a number of slots.

2. Types of Array and Syntax


The different types of arrays are single dimensional, two
dimensional and multidimensional arrays. They can be declared
in java as follows:

1)for single dimensional:

int x[]=new int[5];

2)for 2-d array:

int x[][]=new int[5][4];

3)for multidimensional array:


combination of both 1 and 2nd declaration is allowed.

3. Sample Program

1 public class ArraySample{


2 public static void main( String[] args ){
3 int[] ages = new int[100];
4 for( int i=0; i<100; i++ ){
5 System.out.print( ages[i] );
6}
7}
8}

You might also like