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

Name: Reena Priyadharshini.R Roll No: 17BCC039 Subject: Java Date: 4.7.18

The document is about arrays in Java. It discusses that arrays store homogeneous data in indexed elements and declaring an array is a two-step process of specifying the type and allocating memory. It then shows how to initialize arrays when declaring them by specifying values between curly brackets, which automatically sizes the array. An example prints the number of days in April from a pre-initialized array of month days.

Uploaded by

Naveen Eee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Name: Reena Priyadharshini.R Roll No: 17BCC039 Subject: Java Date: 4.7.18

The document is about arrays in Java. It discusses that arrays store homogeneous data in indexed elements and declaring an array is a two-step process of specifying the type and allocating memory. It then shows how to initialize arrays when declaring them by specifying values between curly brackets, which automatically sizes the array. An example prints the number of days in April from a pre-initialized array of month days.

Uploaded by

Naveen Eee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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 }

You might also like