1 classArrayDemo22 {3 Public Static voidMain (string[] args)4 {5 /*int[] arr= new int[3];6 System.out.println (arr[3]);7 //Arrayindexoutofboundsexception:3 8//When you access a corner label that does not exist in the array, it will occur at run time when the corner is out of bounds exception. */9arr =NULL;//arr does not point to an array entityTenSystem.out.println (arr[0]); One //nullpointerexception: null pointer exception 12//When a reference variable does not have any entities pointing, an exception occurs when a specific entity is manipulated with a change in volume - - the //Both of these issues occur at run time, and compilation does not error - - - } + } - + A classArrAyDemo3 at { - Public Static voidMain (string[] args) - { - /* - int[] arr = new int[3]; - in The second way of defining: - When the array is defined, the length of the array is defined, and the type also defines the contents of the element. to element type [] Array name = new element type []{element, Element, ....}; + - */ the * int[] arr=New int[]{46,98,24};//brackets in the back do not write element lengths $ /*Panax Notoginseng there are several elements in the array, in fact the array is the clearest - The length of the array (number of elements) can be obtained directly from an attribute of the array entity with length the + */ ASystem.out.println ("length=" +arr.length); the for(intx=0;x<arr.length; x + + ) + { - System.out.println (arr[x]); $ } $ /* - The core idea of manipulating an array is that it is a corner mark that can be accessed by an array of elements in a corner: (Set and get) - the usually the most basic action of array manipulation is: traversal. Manipulating arrays by looping - */Wuyi } the}
FAQ for Java_ Arrays