Java Fundamentals 05

Source: Internet
Author: User

We are going to learn the array of knowledge in today's group

The first thing to know is what an array

Concept: array:? For storing multiple data types of the same type, the array is a basic type.

? Index: The number of each data in the array. Start numbering from 0 until the array length-1. This data is the same type of data.

Element (array item)?? : One of the data in an index group

Length: The number of elements in the array, and the length is of type int.

Format: data type [] array name =new data type [length];

? For example: int[] array=new int[5];

Meaning to declare a one-dimensional array of length 5 array? After declaring an array, the system defaults to the default type for the data.

Number type: Default is 0 0.0

Boolean type: Default is False

Char type: Default is ' + '?

String type: default is? null

Other notation int array[]=new int[5];

Assignment array[0]=1;?

array[1]=2;? ?

array[2]=5;?

array[3]=2;?

array[4]=11;?

int [] Array=new int[]{1,2,3,5,6};? Assign values directly in parentheses.

? ? The traversal of an array

First method: For loop traversal

for (int i=0;i

System.out.println (Array[i]);

}?

? second method: Foreach Loop traversal

foreach Loop: Takes each array item in the array sequentially, extracts it once, assigns the array to the variable, executes the loop body, and then removes an assignment to the variable until all the array items in the array have been exhausted.

for (data type; variable name; array name) {

Loop Body Statement

}?

for (int item;array) {

SYSTEM.OUT.PRINTLN (item);

}?

The Foreach loop cannot change the subscript (index), also called a read-only loop. The advantage is that when iterating through a collection, it is much more efficient than a for loop. Collection We'll talk about it in the next place, which is not covered now.

How do you copy an array into another array

Int[] Array1=new int[]{3,2,5,6,7}?;

Int[] Array2=new int[array1.length];

for (int i=0;i

? {Array2[i]=array1[i];

}?

Well, today's array learning ends here, thank you for watching.?

Java Fundamentals 05

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.