Home > Java > javaTutorial > body text

What are the methods defined in java arrays?

PHPz
Release: 2023-04-29 18:25:07
forward
991 people have browsed it

1. Description

An array is an ordered collection of similar data. Arrays describe several data of the same type, arranged and combined in a certain order.

In these factors, each data is called an array element, and each array element can be accessed through a subscript.

2. Three definitions

(1) applies to arrays that do not use initialization. When the array is particularly long, it is not initialized and the values ​​are default values.

Data type [] array name = new data type [array length]

For example

int[] a = new int[3];
Copy after login

Create an array of type int with a length of 3

(2) Suitable for direct initialization of arrays.

Data type [] Array name = {1,2,3}

The length of the array is determined by the number of elements in the curly brackets

int[] arr = {1,2,3};**
Copy after login

(3 ) Anonymous arrays are suitable for transferring parameters directly to methods.

Grammar

new 数据类型[] {1,2,3}
Copy after login

The above is the detailed content of What are the methods defined in java arrays?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template