Array Examples: Part 3
Enhance your knowledge about the arrays with more exciting examples in this lesson.
We'll cover the following...
We have learned one key thing about arrays. There are index and value relations that are very tightly coupled together, this is an advantage. The con is that we cannot change the length of the array. At the time of declaration, initialization, and memory allocation, it is fixed.
Coding example: 37
The following example will depend on the same principles:
Press + to interact
/*How array works : index=>element*/public class ExampleThirtySeven {public static void main (String[] args){//declaring a certain type of array, we choose data type intint[] ageCollection;//the next step deals with allocating memory for elements, we choose 5ageCollection = new int[5];//the initialization process begins with the first elementfor (int i = 0; i <= 4; i ++){int j = 18;j = j + i;ageCollection[i] = j;System.out.println("Element at index " + i + " => " + ageCollection[i]);}}}
Coding example: 38
We have seen how we can create a ...
Access this course and 1400+ top-rated courses and projects.