如何在Java中声明并初始化一个数组?
你可以像声明变量一样声明数组 -
int myArray[];
你可以在使用 new 关键字使用对象一样创建数组 -
myArray = new int[5];
你还可以一个一个的通过索引给数组的每个元素赋值来初始化数组 -
myArray [0] = 101; myArray [1] = 102;
你可以使用索引值来访问数组元素 -
System.out.println("The first element of the array is: " + myArray [0]);
System.out.println("The first element of the array is: " + myArray [1]);
Alternatively, you can create and initialize an array using the flower braces ({ }):
Int [] myArray = {10, 20, 30, 40, 50}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP