search
HomeJavaJavagetting StartedHow to define java array

How to define java array

Nov 12, 2019 am 11:43 AM
java

How to define java array

There are two syntaxes for defining arrays in Java:

Dynamic method (specify the length of the array)

Format: (Recommended learning: java course)

数据类型[] 数组名字 = new 数组存储的数据类型[长度];

[]: Represents an array.

Array name: Give the defined array a variable name that meets the identifier specification. You can use the name to operate the array.

new: keyword, keyword used to create an array.

Data type stored in the array: See what data type the created array is used to store.

[Length]: The length of the array, indicating how many elements can be stored in the array container.

Example:

Define an array container that can store 3 integers. The code is as follows:

int[] arr = new int[3];

Static mode (specify the elements of the array )

Format:

数据类型[] 数组名 = new 数据类型[]{元素1,元素2,元素3...};

Define an array container that stores 1, 2, 3, 4, 5 integers.

int[] arr = new int[]{1,2,3,4,5};

Or omit the format: (You cannot declare first and then assign a value, you can only declare and assign a value at the same time)

数据类型[] 数组名 = {元素1,元素2,元素3...};

Define an array container that stores 1, 2, 3, 4, and 5 integers.

int[] arr = {1,2,3,4,5};

The above is the detailed content of How to define java array. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment