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?
How to Convert ArrayList to Array?
Advertisements
How to convert Arraylist into String Array Java
How to convert java BigDecimal to normal byte array not 2 s complement
Java2
Array to Collection
convert zip file to byte array
collection
Java convert file to byte array
Easy way to transform Collection to Array?
Convert Array to Vector
Javah
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?
How to convert String into java.util.Date
how to convert jsp to exe
How to Prepend Array in PHP
Convert a string representation of a hex dump to a byte array using Java?
how to create array in r
How ro convert char into string??
How to convert XML file to database ?
How to convert string to byte in Java
How to Print Array in JavaScript
How to declare array in Java?
how to convert sql into hql
how to use button in array

Ads