Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java Example – Getting the Array Length

Java Example – Getting the Array Length

Java Examples Java Examples

In this article, we will introduce how to use the length property of an array to get its length.

In the following example, we define a two-dimensional array and get its length:

Main.java File

public

class

Main

{

public

static

void

main

(

String

args

[

]

)

{

String

[

]

[

]

data

=

new

String

[

2

]

[

5

]

;

System

.

out

.

println

(

"

Length of the first dimension:

"

data

.

length

)

;

System

.

out

.

println

(

"

Length of the second dimension:

"

data

[

0

]

.

length

)

;

}

}

The output of the above code is:



第一维数组长度: 2 

第二维数组长度: 5

Java Examples Java Examples