How to define java array: 1. Use [String[] s=new String[6]] to define a string array with a length of 6, and assign values; 2. Use [int[] i =new int[6]], define an integer array with a length of 6.
How to define java array:
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:
The third step, we You can also directly assign values to the array when defining the array. Use String[] str=new String[]{"a","b","c"} to define a string array with a length of 3, as shown in the figure below. Display:
The fourth step is to use int[] ii=new int[]{0,1,2,3} to define an integer array with a length of 4. And assigned values, as shown in the figure below:
The fifth step, we can also use String[] str2={"a","b","c" } method to define an array, as shown below:
Recommended tutorial: "java video tutorial"
The above is the detailed content of How to define array in java?. For more information, please follow other related articles on the PHP Chinese website!