List to Array Java

List to Array Java

Sometimes, in every programming language, it is required to convert DS elements into a string array. This can be done in Java very easily (it is time to prove that Java is simple to practice). Let is see an example on List to Array.

In the following code, an Integer list is converted into String list and also into a String array.

List accepts null values also. For more code manipulation, null is added to Integer list purposefully. Two String lists are generated with the elements of Integer list – one string list accepting null value and the another without accepting null value.

Observe the code on List to Array.

List to Array Java

A generics list numList that stores only Integers is created and added with a null value also.

A string list, stringList is created with the size of integer list, numList.

String.valueOf() converts any data type and object into string form.
toArray() method of Arrays class is used to convert string list into string array.
toString() is used to print array elements of stringArray.

View All for Java Differences on 90 Topics

Leave a Reply

Your email address will not be published. Required fields are marked *