Home > Java > javaTutorial > body text

How to define array length in java

silencement
Release: 2019-05-30 17:45:45
Original
9244 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template