Because:
-array is much more faster than ArrayList.
-To pass an array to a method that is not overloaded to accept collection.
-To integrate collection based code with legacy code that does not understand collection.
Here you need the toArray() defined by Collection.
Example:
import java.util.*;
class demo
{
public static void main(String[] args){
ArrayList
al.add("bhabani");
al.add("pinku");
al.add("mahesh");
al.add("arvind");
al.add("arjan");
String name[]=new String[al.size()];
name=al.toArray(name);
for (String i:name)
{System.out.println(i);}
}};
Nice post. for similar post refer this link How to obtain Array From an ArrayList
ReplyDelete