Basic knowledge of arrays in Java

Source: Internet
Author: User

Array
Feather flock Together
Avg. sum array
The concept of an array [
Arrays: A set of sets with the same data type
]
The syntax of the array [
First declare and then use
Declaring an array:
Data type +[]+ variable name; Data type + variable name +[];
Initialize array: [
1 Dynamic initialization
Array=new data type [length];
The system assigns default values to the elements in the array
2 Static initialization
Array=new data type []{1,2,3,4};
array={1,2,3,4};
]
Declaration and initialization are written together
int [] array=new int[10];
]
Access to array {
We use array subscripts to access arrays.
Subscript: Is the position of the element in the array
Subscript from 0
Array name [subscript of array]; INT[0] Int
}
The unique property of the array {
Length length is read-only and can only be evaluated but cannot be modified
Emphasizes that once an array is created, the length is not variable
Length of Use
Gets the length of the array by the array name.
}
The memory model of the array {sings
Reference data type
The elements of the array are stored in the heap, and the references to the arrays are stored in the stack
}
The traversal of the array {
Iterate through each element of the array in turn
We can iterate through the array by looping.
1 for Loop
2 foreach jdk1.5 [
Syntax is simpler:
For (data type variable name of the array: Target to traverse)
foreach is suitable for the complete traversal of an array
A foreach has no subscript. b foreach cannot assign a value to an array
]
}
}

Basic knowledge of arrays in Java

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.