A summary of the relevant knowledge of arrays in Java (recommended) _java

Source: Internet
Author: User

1,

2, the method of naming the array

1) int[]ages=new int[5];

2) Int[]ages;

Ages=new Int[5];

3) int[]ags={1,2,3,4,5};

4) Int[]ags;

Ags=new int{1,2,3,4};

Or

Int[]ags=new int{1,2,3,4};

3, Java does not support different types of duplicate names array

4. Cyclic assignment of arrays in Java

Package dierge;
 
 public class Shuzu {public
   
   static void Main (String args[]) {
     int[]ags=new int[5];
     int i;
     for (i=0;i<ags.length;i++) {
       ags[i]=i;
       System.out.println ("ags[" +i+ "] is:" +ags[i);}
    }

Print the results as follows:

Ags[0] is: 0
AGS[1] is: 1
AGS[2] is: 2
AGS[3] is: 3
AGS[4] is: 4

5, the initial values of various types of arrays

The code is as follows:

Package dierge;

public class Shuzu {public
  
  static void Main (String args[]) {
    int[]ags=new int[1];
    SYSTEM.OUT.PRINTLN (the default value for an array of int type is: "+ags[0]);
    Boolean[]a=new boolean[1];
    SYSTEM.OUT.PRINTLN ("The default value for the Boolean array is:" +a[0]);
    Byte[]b=new byte[1];
    SYSTEM.OUT.PRINTLN ("The default value of the byte array is:" +b[0]);
    Short[]c=new short[1];
    SYSTEM.OUT.PRINTLN (the default value for the "short type array is:" +c[0]);
    Char[]d=new char[1];
    SYSTEM.OUT.PRINTLN (the default value for the "char type array is:" +d[0]);
    Long[]e=new long[1];
    SYSTEM.OUT.PRINTLN (the default value of the "Long array is:" +e[0]);
    Float[]f=new float[1];
    SYSTEM.OUT.PRINTLN (the default value for the "float type array is:" +f[0]);
    Double[]g=new double[1];
    SYSTEM.OUT.PRINTLN (the default value for the "double array is:" +g[0]);
    
  }

Print the results as follows:

The default value for an array of type int is: 0
The default value for a Boolean array is: false
The default value for the byte array is: 0
The default value for the short type array is: 0
The default values for the char type array are:

The default value for a long array is: 0
The default values for the float type array are: 0.0
The default values for the double array are: 0.0

Above this Java array of relevant knowledge of the summary (recommended) is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

Related Article

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.