Home > Java > javaTutorial > How to declare a one-dimensional array in java

How to declare a one-dimensional array in java

PHPz
Release: 2023-05-10 17:55:06
forward
1420 people have browsed it

1. Definition

An array is a reference data type composed of the same type of data in sequence.

2. Declaration

Syntax format

数据类型[] 数组名; int[] myIntArray; char[] ch; String[] strArray;
Copy after login

Data type

数组名[]; int myIntArray[]; char[] ch; String strArray[];
Copy after login

3.Creation method

//数组创建1:引用,对象,元素
int[] aa;
int[] a = new int[10];
int[] aaa = new int[0]; //空数组
//创建方式2:声明,创建,
int[] b = new int[] {1,2};
String[] strings = new String[] {"Hello World"};
//创建方式3:
int[] c = {1,2,3};
String[] strings2 = {"World"};
Copy after login

The above is the detailed content of How to declare a one-dimensional array in java. 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