How to convert Collection to Array in Java?

How to convert Collection to Array in Java?

Hello,

I have a collection object in data with data in it. How to convert Collection to Array in Java?

Thanks

View Answers

April 13, 2017 at 6:35 AM

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


April 13, 2017 at 6:36 AM

Hi,

Check 100s of Java Util Examples.

Thanks









Related Tutorials/Questions & Answers:
How to convert Collection to Array in Java?
Convert Collection to Array
Advertisements
How to Convert ArrayList to Array?
Collection to Array
difference between java5 and java6 - Java Beginners
How to Convert array to list in Java
Java2
how to convert string to char array in Java
How to convert Arraylist into String Array Java
Array to Collection
about java1
Convert List to Array
Converting Collection to an Array
Converting an Array to a Collection
How to convert java BigDecimal to normal byte array not 2 s complement
Convert Array to String
how to convert string to char array in java without using tochararray
Easy way to transform Collection to Array?
Javah
Convert array to Vector
Convert string into character array
collection
Convert Array to Vector
Convert Array to List
Convert Vector to Array
Java convert file to byte array
convert zip file to byte array
javaa swings - IDE Questions
Convert ArrayList To Array
About Java2
saving form bean with Array of objects (collection) - Struts
Javap Tool application
Maven dependency for com.gooddata - gooddata-http-client version 1.0.0+java7 is released. Learn to use gooddata-http-client version 1.0.0+java7 in Maven based Java projects
Convert a tsring to an array - JSP-Interview Questions
javas - JSP-Servlet
collection
ModuleNotFoundError: No module named 'javax'
ModuleNotFoundError: No module named 'javax'
Convert a string representation of a hex dump to a byte array using Java?
How to: generic array creation
How to Print Array in JavaScript
Collection
how to convert ACSII to HEX
Artifacts of javax
How to Synchronize the Entire collection Frame Work?
How to Prepend Array in PHP
Javah -  Header File Generator
how to create array in r
Collection
How to declare array in Java?

Ads