FAQ for Java_ Arrays

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.