Today’s sharing started, please give us more advice ~

An overview of arrays

1. Array comprehension:

An Array is a collection of data of the same type arranged in a certain order. It is named by a name and centrally managed by numbering these data.

2. Array related concepts:

Array name Element subscript, index Length of an array: Number of elements

3. Array features:

  • Arrays are ordered
  • Arrays are variables that refer to data types. The elements of an array can be either primitive or reference data types
  • Creating an array object creates a contiguous space in memory
  • Once the length of an array is determined, it cannot be modified.

4. Array classification:

① According to the dimension: one dimensional array, two dimensional array.

② According to the type of array elements: array of primitive data type elements, array of reference data type elements

5. Data structure:

  • Logical relationships between data: sets (weak relationships), one-to-one (elements in arrays), one-to-many (binary trees), many-to-many (social networks)
  • Data storage structure: linear table: sequential table (such as: array), linked list, stack, queue tree structure: binary tree graph structure:

2. One-dimensional arrays

1. Declaration and initialization of one-dimensional arrays

The right way:

The wrong way:

2. One-dimensional array element references:

Call using corner markers.

3. Array properties:

Array property: length

Description: Once an array is initialized, its length is fixed. Arr. length Once the array length is specified, it cannot be modified.

4. Traversal of one-dimensional arrays

5. Default initialization values for one-dimensional array elements

  • The array element is an integer: 0
  • The array elements are floating point: 0.0
  • Array elements are char: 0 or ‘\u0000’, not ‘0’
  • Array elements are Boolean: false
  • Array elements are reference data type: NULL

6. Memory structure of one-dimensional arrays

Three, two dimensional array

1. How to understand two-dimensional arrays?

An array that is A reference data type can also be A reference data type an element of A one-dimensional array A if it’s still A one-dimensional array, then array A is called A two-dimensional array.

2. Declaration and initialization of two-dimensional arrays

The right way:

The wrong way:

3. How to call a two-dimensional array element:

4. Array properties:

5. Iterate over two-dimensional array elements

6. Default initialization values for two-dimensional array elements

7. Memory structure of two-dimensional arrays

Common algorithms for arrays

1. Array creation and element assignment:

Yang Hui triangle (two-dimensional array), loop number (two-dimensional array), 6 numbers, randomly generated between 1-30 and not repeated.

Yang hui triangle

2. For numeric arrays:

Maximum, minimum, sum, average, etc

3. Array assignment and copy

3.1 the assignment

Assigns the address value of the array held by Array1 to Array2 so that array1 and Array2 both point to the same array entity in the heap space.

3.2 copy:

We give Array2 a new array space in the heap using new. Assigns the values of the elements in Array1 to array2 one by one.

4. Array element inversion:

5. Search for the specified element in the array: search, retrieve

5.1 Linear Search:

Implementation idea: through the way of traversal, a comparison of data, find. Applicability: Universal adaptability

5.2 Binary Search:

Implementation ideas: every time the comparison of intermediate value, half way to retrieve. Applicability: (Prerequisite: array must be ordered)

6. Array sorting algorithm

Ten sorting algorithms

  • Selection sort:
  • Directly select sort, heap sort
  • Swap sort:
  • Bubble sort, quick sort
  • Insert sort:
  • Direct insertion sort, half-broken insertion sort, Hill sort
  • Merge sort
  • Bucket sort
  • Radix sort

To understand:

1) Measure the advantages and disadvantages of the sorting algorithm:

Time complexity, space complexity, stability

2) Sort classification: internal sort and external sort (need to use disk)

3) Time complexity of different sorting algorithms

Bubble sort implementation:

The use of Arrays utility classes

1. To understand:

① Defined in the java.util package. ② Arrays: Provides many ways to manipulate Arrays.

2. Use:

Common exceptions to arrays

1. Out-of-bounds exception of array corner markers:

ArrayIndexOutOfBoundsException

2. Null pointer exception

NullPointerException

Tip: Once the program is abnormal, unhandled, the execution will be terminated.

Today’s share has ended, please forgive and give advice!