Java Array notes

Source: Internet
Author: User
Tags array length

# array--------Memory #

2017/8/31 15:29:19

# # Array (container) # #
-to store multiple values of the same data type
-Concept
-an array is a collection of multiple elements that can store the same data type, or it can be seen as a container
-Arrays can store either the base data type or the reference data type
-Format
-data type [] Array name = new data type [length of array];
-int[] arr = new INT[5];
-data type [] Array name = new data type []{element 1, Element 2, Element 3, ...};
-int[] arr = new int[]{11,22,33,44,55};---------Array length is 5
-Array Initialization
-Creates contiguous memory space for arrays and assigns values to each array element
-Dynamic Initialization: Specifies the length only, the system determines the initialization value
-int[] arr = new INT[5];
-
1. Integer type: Byte,short,int,long, default initialization value is 0
2. Floating-point type: float,double, default initialization value is 0.0
3. Boolean type: Boolean default initialization value is False
4. Character type: Char initialization value is ' \u0000 '-------Char occupies two bytes in memory, 16 bits, \u0000----each 0 represents 16, 0 four is 0 bits
-Static initialization: Given the initialization value, the system determines the length of the
-data type [] Array name = new data type []{element 1, element 2,...};
-' int[] arr = new int[]{11,22,33,44,55}; ' Declare first, then assign value
-' int[] arr = {11, 22,33,44,55}; ' Declaration and assignment in one row

' int[] arr;

arr = new int[]{11,22,33,44,55};

Int[] ARR2;
ARR2 = {11,22,33,44,55}//Will error,,, Declaration and assignment must be in one row
`

# # Stack # #
-Store Local Variables---
-Local variables: variables defined on the method declaration and in the method
-int x = 10;
# # heap # #
-Store new array or object (newly created)
# # Method Area # #
-Object-oriented-
# # Local Method Area # #
-related to the system
# # Register # #
-For CPU use (. Class)

# # An array of memory plots # #
! [] (Http://i.imgur.com/HCpk6gu.png)

# Two-dimensional array #

' int[][] arr = new int[3][2]; Defining a two-dimensional array
System.out.println (arr); Two-dimensional array [[email protected]
System.out.println (Arr[0]); The first one-dimensional array in a two-dimensional array [[email protected]
System.out.println (Arr[0][0]); The first element of the first one-dimensional array in a two-dimensional array 0


/*
int[][] arr = new int[3][2];
The following two types are also formats that represent arrays
int arr[][] = new int[][];
Int[] arr[] = new int[][];

int x;
int y;
int x, y;

Int[] x;
Int[] y[];

Int[] x,y[]; X is a one-dimensional array, and Y is a two-dimensional array
*/`

**int[][] arr = new int[3][];**

----------a two-dimensional array with three one-dimensional arrays

Assignment::

' arr[0] = new INT[3];
ARR[1] = new INT[5];
`
# #二维数组遍历 # #
Outer loop control of the length of the two-dimensional array is actually the number of one-dimensional arrays;

The inner loop controls the length of a one-dimensional array.


' Class Demo2_array {
public static void Main (string[] args) {
Int[][] arr = {{1,2,3},{4,5,6},{4,3}};
System.out.println (arr);
System.out.println (Arr[0]);
System.out.println (Arr[0][0]);

Bianli (arr);
}
public static void Bianli (int[][] arr) {
for (int i = 0; i < arr.length; i++) {//i represents a one-dimensional array in each of the two-dimensional arrays
for (int j = 0;j < Arr[i].length; J + +) {
System.out.print (Arr[i][j] + "");
}
System.out.println ();
}
}
}`


# parameter Passing in Java #

1. The value of the base data type is passed without changing the original value because the stack is popped after the call and the local variable disappears.
2. The value of the reference data type is passed, changing the original value, because even if the method pops up the stack, but the object of the heap memory array is still there, you can continue to access through the address.

* Two kinds of statements:

1, Java is not only the value of the pass, but also the address, the basic data type passed the value of the reference data type of the addresses passed

2. Only value is passed in Java because the address value is also a value *

Java Array notes

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.