Friday, March 13, 2020

Know More About Arrays in Java

It is the most widely used language by selenium experts for selenium testings as it is highly user-friendly and makes testing easier. Java has many special features that make it user-friendly and arrays in Java are one such special feature.

The term “Array” denotes a group of similar types of elements that have almost the same memory location. In java, an array is an object that contains elements of similar data type. More clearly, an array in Java can be defined as a data structure where similar objects are stored. An Array in java is index based and the first element will be stored in 0 indexes.

The advantage of an array in java is that it makes retrieval or sorting of code easier and it allows random access. At the same time, it has one disadvantage too. Only fixed size elements can be stored in an array and it will not grow as the program runs.

Different Types of Arrays in Java

Basically, there are two types of arrays in java and they are one and two-dimensional arrays. They are better known as a single dimensional array and multi-dimensional array.

An Array can be passed to methods in java and so that the logic can be reused on any array.

Example for Single Dimensional Array


class Testarray{

public static void main(String args[]){

int a[]=new int[5];//declaration and instantiation

a[0]=10;//initialization

a[1]=20;

a[2]=70;

a[3]=40;

a[4]=50;

//printing array

for(int i=0;i<a.