Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Good programmer big data tutorials share practical arrays of big data

Shulou Source: shulou.com Published: 2022-06-03 07:40:28 09月28日 Update

Good programmer big data tutorials share practical arrays of big data

1.5.1 Array definition and element access

An array is a container that stores a specified data type.

Note:

An array is a container of fixed length. Once the instantiation is completed, the length cannot be modified.

The noun explains:

Array length: refers to the capacity of the container, indicating how many data elements can be stored in the array: refers to the data subscript stored in the array: an element is indexed in a position in the array to traverse the array: get each element in the array in turn

Element access to array

Accessed by subscript, the subscript of the elements in the array starts at 0

The subscript of the element in the array: [0, array .length-1]

Note:

When accessing the elements in the array, pay attention to the range of the subscript, do not cross the boundary!

Traverse the array:

Use looping through the subscript

Int [] array = {1,2,3}; for (int index = 0; index < array.length; index++) {System.out.println (index);}

Use enhanced for loops

Int [] array = {1,2,3}; for (int ele: array) {System.out.println (ele);} memory analysis of 1.5.2 array common operations of 1.5.3 array 1.5.4 array sort

Select sort

Fix a subscript, and then compare the elements corresponding to this subscript with the elements of each subscript that follow.

Int [] array = {1,3,5,7,9,0,8,6,4,2}; for (int index = 0; index < array.length-1; index++) {for (int compare = index+ 1; compare < array.length; compare++) {if (array [index] < array [compare]) {int temp = array [index]; array [index] = array [compare]; array [compare] = temp }}}

Bubbling sort

Compare two adjacent elements in an array in turn

Int [] array = {1, 3, 5, 7, 9, 0, 8, 6, 4, 2}; for (int I = 0; I < array.length; iDeposit +) {for (int j = 0; j < array.length-1-I; jaun +) {if (array [j] < array [j + 1]) {int temp = array [j]; array [j] = array [j + 1] Array [j + 1] = temp;}} 1.5.5 array element lookup

Query the subscript that appears for the specified element from an array

Sequential search binary search 1.5.6 two-dimensional array

Tags: Array element subscript data container storage sort that is length loop utility tutorial program programmer two item location memory noun noun interpretation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology macOS Docker Shulou Information