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?
How to Convert array to list in Java
how to convert string to char array in Java
How to convert Arraylist into String Array Java
How to convert java BigDecimal to normal byte array not 2 s complement
Java2
Convert List to Array
how to convert string to char array in java without using tochararray
Converting Collection to an Array
Convert Array to String
Array to Collection
Converting an Array to a Collection
Convert array to Vector
collection
convert zip file to byte array
Java convert file to byte array
Convert ArrayList To Array
Easy way to transform Collection to Array?
Javah
Convert Array to List
Convert Vector to Array
Convert Array to Vector
how to convert ACSII to HEX
how to convert string to image in java
How to convert into to String in Java?
How to: generic array creation
How to convert NSString to NSInteger?
How to Convert String to Date?
How to convert a String to an int?

Ads