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

How to define an array in Java

王林
Release: 2019-11-13 13:05:14
Original
16654 people have browsed it

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!

Related labels:
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template