Home  >  Article  >  Java  >  How to define array length in java

How to define array length in java

silencement
silencementOriginal
2019-05-30 17:45:459206browse

How to define array length in java

Array definition in java:

There are two syntaxes for defining arrays in Java:

type arrayName[];
type[] arrayName;
type is any data type in Java, including basic types and combined types. arrayName is the array name and must be a legal identifier. [ ] indicates that the variable is An array type variable. For example:

int demoArray[];int[] demoArray;

There is no difference between these two forms, and the usage effect is exactly the same. You can choose according to your own programming habits.

String array:

##1、String[] str=new String[5]

2、String[] str= new String[]{"a","b"}

3. String[] str={"a","b"}

Integer array:

1. int[] i=new int[5]

2, int[] i=new int[]{0,1}
3, int[] i={0,1}

Other array definition methods are similar.


The above is the detailed content of How to define array length in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn