Home >Java >Javagetting Started >How to define an array in Java
1. You can use String[] s=new String[6] to define a string array with a length of 6. After definition, you can assign values to the string array, as shown below As shown:
2. Use int[] i=new int[6] to define an integer array with a length of 6. Other types are similar, as shown in the figure below :
3. When defining the array, you can directly assign values to the array, using String[] str=new String[]{"a","b", "c"}Define a string array with a length of 3, as shown below:
4. Use 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 following figure:
5. You can also use String[] str2= {"a","b","c"} method to define an array, as shown below:
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!