An array of strings
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
An array of integers
int[] myNum = {10, 20, 30, 40};
Change an Array Element
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; cars[0] = "Opel"; System.out.println(cars[0]); // Now outputs Opel instead of Volvo
Array Length
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"}; System.out.println(cars.length); // Outputs 4
Multidimensional Arrays
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
Access Elements
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} }; System.out.println(myNumbers[1][2]); // Outputs 7
Change Element Values
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} }; myNumbers[1][2] = 9; System.out.println(myNumbers[1][2]); // Outputs 9 instead of 7
标签:Java,Arrays,cars,myNumbers,System,int,Volvo,out From: https://www.cnblogs.com/ShengLiu/p/16924016.html