How to define an array in java: 1. Use [String[] s=new String[]] to define a string array; 2. Use [int[] i=new int[]] to define an integer array; 3. Use [String[] str2={"a", "b", "c"}] to define the array.
The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer. This method is suitable for all brands of computers.
How to define an array in java:
In the first step, we can use String[] s=new String[6]
, define a string array with a length of 6. After definition, you can assign values to the string array, as shown in the following figure:
The second step is to use int[] i=new int[6]
, define an integer array with a length of 6, other types are similar, as shown below:
Third Step, we can also directly assign values to the array when defining the array, using String[] str=new String[]{"a","b","c"}
define an array with a length of 3 string array, as shown below:
int[] ii=new int[]{0,1,2, 3}Define an integer array with a length of 4 and assign a value, as shown in the figure below:
String[] str2={"a","b","c"} way to define the array, as shown below:
Related free learning recommendations: java basic tutorial
The above is the detailed content of How to define an array in java. For more information, please follow other related articles on the PHP Chinese website!