Skip to content

Commit 50e629e

Browse files
committed
update java program to convert arraylist to array
1 parent 80b7dcd commit 50e629e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

collections/arraylist/convert-arraylist-to-array/ArrayListToArray2.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ public static void main(String[] args) {
2828

2929
// convert ArrayList to array
3030
// pass a new String array of the arrayList size as a param to toArray
31-
String[] elements = arrayList.toArray(new String[arrayList.size()]);
31+
//String[] elements = arrayList.toArray(new String[arrayList.size()]);
32+
33+
//kindly read the 'Important Note' below
34+
String[] elements = arrayList.toArray(new String[0]);
3235

3336
System.out.println("\nArray:");
3437
//we will receive the string array, so iterate on it to print each element

0 commit comments

Comments
 (0)