The concept of Java arrays

Source: Internet
Author: User
Tags array sort
An array is a collection of data, and an array is also a Java object, and an element in an array can be of any type (including basic and reference types).
To specify the length of the array declaration,
The new statement performs the following steps, allocating memory space for an array in the heap, such as creating an array of int with 100 elements, each
are of type int, occupy 4 bytes, so the entire array object occupies 400 bytes in memory, and each element in an array gives its data
The default value of the type, int is 0,boolean is false,string is null, returns the reference to an array object, after the array object is created,
His length is fixed and the length of the array object cannot be changed, but the array variable can change the referenced array object.
The Java array inherits the object class, thus inheriting all the methods of the object class, the Equals method of the array object, and using the instanceof action
Character to determine the type of the array, the ToCharArray () method of the String class can return an array containing all the characters in the string.
Array sort, bubbling sort,
The easiest way to find specific data from an array is to iterate through all the elements in the array, called a linear lookup, and the IndexOf () method is used to find the index position of the element that values value in array arrays
The time complexity of linear lookup is O (n), which is suitable for small arrays or unsorted arrays, and for large arrays, the efficiency of linear lookups is low, and an efficient two-fork tree algorithm is available for arrays that have been sorted.
The algorithm finds the element in the middle of the array, compares it to its lookup value, and returns the index of the element if the two are equal, otherwise the problem is reduced to finding half the elements of the sorted array--If the lookup value is less than
An intermediate element of an array that looks for the first half of the array, otherwise it looks for the second half of the array, and the time complexity of the binary lookup is O (log2n), that is, the logarithm of N to 2.
Array implementation class: Arrays,java.util.arrays the implementation class of an array of operations, equals compares the elements in two arrays, fill () fills the array with data, sort () sorts the elements in the array in ascending order
If the element in the array is a reference type, a natural sort, binarysearch () finds the element in the array with the same value as the given data according to the binary lookup algorithm, provided that the elements in the array are in ascending order,
ToString returns a string containing information about all elements in the array, and fill (boolean[]a,boolean var) sets the value of all elements in the Boolean array to Var
The System.arraycopy (a1,0,a2,0,a1.length) method copies the contents of the A1 array into the A2 array,
Related Article

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.