What are Arrays ?

I hope most of you know that what are arrays but do you really know it ?
Arrays are named memory location in which we can store a no. of elements of the same type in a single location or variable.

They are like boxes in which we can fill different thing instead of placing each object of same type in different places. They help us to ease the trouble of making different variables to store different values of same type. For example if you want to store first 100 natural nos, then you will have to make 100 different variables to store each natural no separately. But here arrays come to our rescue by helping us in storing all the first 100 nos to store in a single variable.

Syntax to declare and initialize an array.

int a[] = new int[size of array];

for(int i = 0; i < a.length; i++)

a[i] = Integer.parseInt(br.readLine());

Same way you can do this for other data types.

Now for static initialization

int a[] = new int[]{elements};


int a[] = {elements};


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s