Home > Java > javaTutorial > How to define array in java?

How to define array in java?

coldplay.xixi
Release: 2020-06-28 10:44:16
Original
9212 people have browsed it

How to define java array: 1. Use [String[] s=new String[6]] to define a string array with a length of 6, and assign values; 2. Use [int[] i =new int[6]], define an integer array with a length of 6.

How to define array in java?

How to define java array:

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 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 array in java?

The third step, we You can also directly assign values ​​to the array when defining the array. Use String[] str=new String[]{"a","b","c"} to define a string array with a length of 3, as shown in the figure below. Display:

How to define array in java?

The fourth step is to use int[] ii=new int[]{0,1,2,3} to define an integer array with a length of 4. And assigned values, as shown in the figure below:

How to define array in java?

The fifth step, we can also use String[] str2={"a","b","c" } method to define an array, as shown below:

How to define array in java?

Recommended tutorial: "java video tutorial"

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