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

How to define an array in java

coldplay.xixi
coldplay.xixiOriginal
2021-02-26 14:36:0249775browse

How to define an array in java: 1. Use [String[] s=new String[]] to define a string array; 2. Use [int[] i=new int[]] to define an integer array; 3. Use [String[] str2={"a", "b", "c"}] to define the array.

How to define an array in java

The operating environment of this tutorial: windows7 system, java10 version, DELL G3 computer. This method is suitable for all brands of computers.

How to define an array in java:

In the first step, we can use String[] s=new String[6] , define a string array with a length of 6. After definition, you can assign values ​​to the string array, as shown in the following figure:

How to define an array in java

The second step is to use int[] i=new int[6], define an integer array with a length of 6, other types are similar, as shown below:

How to define an array in java

Third Step, we can also directly assign values ​​to the array when defining the array, using String[] str=new String[]{"a","b","c"}define an array with a length of 3 string array, as shown below:

How to define an array in java

##Step 4. Use

int[] ii=new int[]{0,1,2, 3}Define an integer array with a length of 4 and assign a value, as shown in the figure below:

How to define an array in java

The fifth step, we can also use

String[] str2={"a","b","c"} way to define the array, as shown below:

How to define an array in java

Related free learning recommendations: java basic tutorial

The above is the detailed content of How to define an array 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