Skip to content

Commit b6ff9cb

Browse files
authored
Merge pull request #17054 from sk1418/impr-array-length
[impr-array-length] array length
2 parents dff38db + eb9c86e commit b6ff9cb

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/ArrayReferenceGuide.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.baeldung.array;
22

3+
import java.lang.reflect.Array;
34
import java.util.ArrayList;
45
import java.util.Arrays;
56
import java.util.Comparator;
@@ -14,6 +15,8 @@ public static void main(String[] args) {
1415

1516
initialization();
1617

18+
getLength();
19+
1720
access();
1821

1922
iterating();
@@ -44,6 +47,16 @@ private static void initialization() {
4447
int[] anotherArray = new int[] {1, 2, 3, 4, 5};
4548
}
4649

50+
private static void getLength() {
51+
int[] anArray = new int[] { 1, 2, 3, 4, 5 };
52+
System.out.println("anArray's length: " + anArray.length);
53+
54+
System.out.println("[Array.getLength()] anArray's length: " + Array.getLength(anArray));
55+
56+
Object arrayAsObj = anArray;
57+
System.out.println("the array Object (anArray) 's length: " + Array.getLength(arrayAsObj));
58+
}
59+
4760
private static void access() {
4861
int[] anArray = new int[10];
4962
anArray[0] = 10;
@@ -156,4 +169,4 @@ private static void merge() {
156169
}
157170
}
158171

159-
}
172+
}

0 commit comments

Comments
 (0)