To convert collection-based data into array we can use toArray() method provided by the implementation of Collection interface such as java.util.ArrayList. Our sample code result is shown below:
import java.util.List;
import java.util.ArrayList;
public class CollectionToArrayExample
{
public static void main(String[] args)
{
List list = new ArrayList();
list.add("Java");
list.add("Sample");
list.add("Code");
Object[] array = list.toArray();
for (int i = 0; i < style="color: rgb(0, 102, 0);">length; i++)
{
System.out.println(array[i].toString());
}
}
}
Java
Sample
Code
Click Here to See Answer .....
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.
0 comments:
Post a Comment