The three formats for defining arrays are as follows:
int[] arr1=new int[10]; int[] arr2={1,2,3,6}; int[] arr3=new int[]{1,2,3,4,5,6,7,22};Note: the length of the array is an attribute, and the length() of the string is a method! ! ! Although they are asking for their respective lengths
package day 4; public class array {public void showArray(int[] arr){for(int i=0;i<arr.length;i++)System.out.print(arr[i]+"/t");System.out.println();}public static void main(String[] args) {int[] aa;//System.out.println(aa);//It just declares that the array cannot be used without initial value, and an error message will be reported). If new comes out, the values of the system's complex int type are 0int[] arr1=new int[10];//The size must be specified int[] arr2={1,2,3,6};System.out.println(arr2[0]);int[] arr3=new int[]{1,2,3,4,5,6,7,22};//Note that the size cannot be specified, this most commonly used array shuzu=new array();shuzu.showArray(arr1);shuzu.showArray(arr2);shuzu.showArray(arr3);shuzu.showArray(new int[]{1,3,2,33});//Yes, the correct assignment //shuzu.showArray({2,4,1});//Error, the compile error is reported}}The above is the entire content of the three types of Java definition arrays that the editor brings to you. I hope it will be helpful to you and support Wulin.com more~