+ 3
In array, what is the uses of index
2 odpowiedzi
+ 6
Array helps you to store a bunch of values with the same type with just a single variable name (Or array name), However, as it stores more than one value, you need to make sure you use the correct one which you want. Therefore index is needed to locate and acces the specific value that you want, for example:
int arr[] = {0,1,2,3,4};
In order to access 1 I need to use index of 1 which means the second "place" in the array (array index count from 0 in Java)
System.out.println(arr[1]);
With this I could print out the value 1, if there is no index, it will be
System.out.println(arr);//this will print out the address(I guess) of the array not the value
Therefore, without index, we can't specify which value in the array to be used.
IN BRIEF: Index is use to access the value in the specific "place" of the array.(this is not technical enough)
0
Index helps u to access elements in the array.