Java Basics--array review

Source: Internet
Author: User

An array is a variable, a set of data that stores the same data type is declared a variable is a block of space in the memory space to declare an array is a contiguous array of spatial arrays in memory space fixed, avoid array out of bounds   array is statically allocated memory space, All elements are stored in a contiguous set of storage units, once assigned, cannot be changed, is not easy to expand, the array is easy to find and modify, and is not conducive to insertion and deletion.   Using arrays:   ① declaring arrays    ② allocating space    ③ assignment    ④ processing data in Java array definitions to specify the length. data type [] Array name = new data type [array length]; data type [] Array name = new data type [number of rows] [number of columns]; Gets the length of the array = array name. length; Gets the element in the array = array name [subscript];   &NBSP;&NB sp;       element subscripts from 0 to length-1 assign values to arrays: array name [corresponding subscript] = assigned value;  array sort:   ① Select sort: Let each number in the array, followed by The subsequent number is compared, and the position is exchanged if the previous number is greater than the subsequent number.             The first number is compared to the number in the back, and the smallest number is the first when the comparison is completed.         for (int i= 0; i< arr.length-1; i++) {          & nbsp for (int j=i+1;j<arr.length;j++) {                     int temp;                    if (arr [i] > Arr[j]) {                        TEMP = arr[i];& nbsp                       Arr[i] = arr[j];                         ARR[J] = temp;                    }                }        }        ② Bubble Sort: Two adjacent numbers are compared, the first wave compares, the largest number is at the end. (after each comparison, the following number decreases a comparison)         for (int i = 0; i < arr.length-1; i++) {    &nbs p;       for (int j = 0; J < Arr.length-1; J + +) {         &nbs P      if (Arr[j] > arr[j+1]) {                    Int temp = arr[j];               & nbsp;    ARR[J] = arr[j+1];                     Arr[j+1] = temp;                }             }        }

Java Basics--array review

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.