<aside> 💡 Sequence of elements of the same type and fixed size.

</aside>


What is it for?

Organizing data of the same type, including objects, and that have some kind of relationship among them. They have a fixed size, and their elements cannot be removed, nor can new ones be added. What happens is an exchange; an element at a certain position becomes another, possibly changing its place or no longer existing in the array. However, the position still exists, and the sequence remains the same size.


How to instantiate it?

It’s simple. Just specify a type, give it a name, and instantiate an object of this type with a fixed size inside square brackets.

int[] numbers = new numbers[10];

Alternatively, instead of instantiating an object, you can simply place the elements within curly braces.

int[] numbers = {1, 2, 3, 3, 22, 06};

I didn't place the elements inside an array, I just created it. What now?

Congratulations, now you have an array full of null pointers. Be careful with them. To learn more about it, click on the link below.

Exception Handling

But, arrays with nothing in them are useless if you never use them. So, right after learning how to create an array, you need to learn how to use them.


How to access its elements?

Via index. What does that mean? Basically, by position. Each element has its position in the sequence, and access is done using square brackets and the desired position.

The position varies from 0 to the size of the array -1. If an array has 10 elements, the positions range from 0 to 9.

You can assign the desired value, as long as it is of the correct type, to each position in the sequence using its indexes.