Array classification:
1. Divide the index array into index array and associative array from the subscript of the array
The code copy is as follows:
/* Index array, that is, the array usually referred to as */
var ary1 = [1,3,5,8];
//Click the array element by index, starting from 0 (of course, some language implementations start from 1)
//The index is actually an ordinal number, an integer number
alert(ary1[0]);
alert(ary1[1]);
alert(ary1[2]);
alert(ary1[3]);
/* Associative array refers to an array accessed with non-ordinal type as a subscript in Python called dictionary*/
var ary2 = {};
//When accessing, use non-ordinal numbers (numbers), here is a string
ary2["one"] = 1;
ary2["two"] = 2;
ary2["thr"] = 3;
ary2["fou"] = 4;
2. Divide data into static arrays and dynamic arrays from the storage of data.
The code copy is as follows:
// Static array in java
// After definition, the length of the array is fixed and cannot be changed. The array elements are retrieved by index.
Int[] ary1 = {1,3,6,9};
// Dynamic array in java
// The ArrayList implementation in java is based on Array. Here we say that dynamic arrays are generalized, no matter what method is implemented.
List<Integer> ary2 = new ArrayList<Integer>();
ary2.add(1);//Elements can be added dynamically, and the length of the array also changes with the change.
ary2.add(3);
ary2.add(6);
The code copy is as follows:
/* js array belongs to dynamic array*/
var ary = [];//Define an array, no length specified
ary[0] = 1;//You can add elements dynamically
ary.push(3);
ary.push(5);
alert(ary.join(","));//Output 1,3,5
The array of js belongs to both index arrays and dynamic arrays, because in essence it is a js object, reflecting the characteristics of js dynamic language. However, the index array of js does not "continuously allocate" memory, so the indexing method does not bring high efficiency. Arrays in Java are continuously allocated memory.