Home >Java >Javagetting Started >How to define an array in Java

How to define an array in Java

王林
王林Original
2019-11-13 13:05:1416593browse

How to define an array in Java

1. You can use String[] s=new String[6] to define a string array with a length of 6. After definition, you can assign values ​​to the string array, as shown below As shown:

How to define an array in Java

2. Use int[] i=new int[6] to define an integer array with a length of 6. Other types are similar, as shown in the figure below :

How to define an array in Java

3. When defining the array, you can directly assign values ​​to the array, using String[] str=new String[]{"a","b", "c"}Define a string array with a length of 3, as shown below:

How to define an array in Java

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 following figure:

How to define an array in Java

5. You can also use String[] str2= {"a","b","c"} method to define an array, as shown below:

How to define an array in Java

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