Hello,
I have a collection object in data with data in it. How to convert Collection to Array in Java?
Thanks
Hi,
You can use the following code to create a collection:
List<String> myList = new ArrayList<String>(); list.add("This ");
Above code create a collection and then add an item to it.
Now to convert it into list myList.toArray() function can be used which converts Collection to Array in Java.
Here is the code for converting Collection to Array:
String[] s1 = myList.toArray(new String[0]);
Check complete tutorial at Converting Collection to an Array.
Thanks
Ads