NAME : REENA PRIYADHARSHINI.
ROLL NO : 17BCC039
SUBJECT : JAVA
DATE : 4.7.18
Arrays
Arrays in Java are homogeneous data structures implemented in Java as objects. Arrays
store one or more values of a specific data type and provide indexed access to store the same. A
specific element in an array is accessed by its index. Arrays offer a convenient means of
grouping related information.
Obtaining an array is a two-step process.
First, you must declare a variable of the desired array type
Second, you must allocate the memory that will hold the array, using new, and assign it
to the array variable
So, let us see how can we declare arrays in different ways.
General Form of Java Array Initialization
Example:- int month_days[];
General Form of Java Array Initialization
Example:-
Arrays can be initialized when they are declared. The array will automatically be created
large enough to hold the number of elements you specify in the array initializer. There is no need
to use new.Now, let us see how we can implement this.
General Form of Java Array Initialization
The following code creates an initialized array of integers:
1 class MyArray{
2
3 public static voide main(String args[]){
4
5 int month_days[ ] = {31,28,31,30,31,30,31,30,31,30,31};
6
7 System.out.println("April has " + month+days[3] + "days.");
8
9 }
10
11 }