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.
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:
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:
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:
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:
String[] str2={"a","b","c"} way to define the array, as shown below:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.