Arrays in Java

Source: Internet
Author: User

1, you can create an array of your own classes, but your own class must implement the Get () and put functions

2, declare array: int[] arrayofint. Note that you cannot specify a size when you define an array

3, create and initialize: via new. arrayofints = new int[42]; can also be merged: double[] numbers = new double [5];

Importjava.util.Arrays;/*** Created by Jimmy on 2015/5/24.*/ Public classArraytest { Public Static voidMain (string[] args) {//1-Statement        int[] arrayofints; //Initialization Method 1Arrayofints =New int[42]; //Initialization Method 2        Double[] Doublenums =New Double[20]; //Initialization Method 3        int[] ArrayOfInt1 = {1,2,3,4,5,6}; //2-Copy//arraycopyString[] names = {"Ryan", "Tim", "Shark", "Ted"}; String[] Tmparray=NewString[names.length * 2]; System.arraycopy (names,0, Tmparray, 0, 4); //copyOfstring[] NameArray =arrays.copyof (names, names.length); NameArray= arrays.copyof (names, Names.length + 2); //Copyofrange, excluding the to elementNameArray = Arrays.copyofrange (names, 1, 3); //Enhanced for loop traversal arraySYSTEM.OUT.PRINTLN ("Copy function test:");  for(String D:namearray) System.out.print (" " +d);        System.out.println (); //3-Multidimensional Arrays        Boolean[] checked; Checked=New Boolean[3][]; checked[0] =New Boolean[8]; checked[1] =New Boolean[8]; checked[2] =New Boolean[8]; System.out.println ("MultiArray test:");  for(Boolean[] b:checked) {             for(Booleanbv:b) System.out.print (BV+ " ");        System.out.println (); }        //System.out.println (doublenums.tostring ());    }}

Arrays in Java

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.