How to convert Collection to Array in Java?

Ads
 

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

Ads









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 Arraylist into String Array Java
Java2
How to convert java BigDecimal to normal byte array not 2 s complement
Convert List to Array
about java1
Converting Collection to an Array
Array to Collection
Convert Array to String
Converting an Array to a Collection
collection
Convert string into character array
convert zip file to byte array
Convert array to Vector
Javah
Java convert file to byte array
Convert ArrayList To Array
Easy way to transform Collection to Array?
Convert Array to List
Convert Vector to Array
Convert Array to Vector
javaa swings - IDE Questions
About Java2
how to convert ACSII to HEX
how to convert string to image in java
How to convert into to String in Java?
Javap Tool application

Ads