Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 50e629e

Browse files
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)

AltStyle によって変換されたページ (->オリジナル) /