Learn Java Coding

Everything You Have To Know About Java

Arrays

You use an array to group values/objects. An array is like a collection of things.

array collection java

In previous example OBJECTS; we were making an inventory system. For an inventory system it is necessary to group objects, therefore we need this theory.

Theory

An array are boxes, in which you save data:

array java

As you can see the boxes are empty.

This is what displayed picture looks like in Java
Boxes [] emtpyBoxes = new Boxes[3];

To fill an array, you use this code:

arrayName [place in the array where you want to add] = object you want to add;

Example

Using the previous inventory example (OBJECTS).

  1. First we’ve to create the object:
Furniture redChair = new Furniture();

2. Then you can add the object, to the collection

tableCollection[0] = redChair;

 

 

GO TO NEXT

Next Post

Previous Post

© 2019 Learn Java Coding