Here's just some of what you'll learn?

Java Arrays

An array is a collection of similar data types. Array is a container object that hold values of homogeneous type. It is also known as static data structure because size of an array must be specified at the time of its declaration.

Array starts from zero index and goes to n-1 where n is length of the array.

In Java, array is treated as an object and stores into heap memory. It allows to store primitive values or reference values.

Array can be single dimensional or multidimensional in Java.

Features of Array

  • It is always indexed. Index begins from 0.
  • It is a collection of similar data types.
  • It occupies a contiguous memory location.
  • It allows to access elements randomly.

Single Dimensional Array

Single dimensional array use single index to store elements. You can get all the elements of array by just increment its index by one.

 

Array Declaration

Syntax :

datatype[] arrayName;;

or

datatype arrayName[];

Java allows to declare array by using both declaration syntax, both are valid.

The arrayName can be any valid array name and datatype can be any like: int, float, byte etc.

Example :

int[ ] arr;

char[ ] arr;

short[ ] arr;

long[ ] arr;

int[ ][ ] arr;

Initialization of Array

Initialization is a process of allocating memory to an array. At the time of initialization, we specify the size of array to reserve memory area.

Initialization Syntax

arrayName = new datatype[size]

 

 

 

Powered by Froala Editor

Learn to code in Java programming language step-by-step at SkillRary, and make your first unique, advanced program in just few days.
Arrays Coding Challenges

5 Coding Challenges

Start Practice