7:52 pm - Thursday October 18, 2018

ArrayList Example Program for toArray()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of
toArray().It is used  to return arrayList into array
*/
import java.io.*;
import java.lang.*;
import java.util.*;
public class ArrayListToArray
{
public static void main(String arg[])throws Exception
{
ArrayList al=new ArrayList();//to create object for ArrayList class
al.add("A");//to add an element in arrayList
al.add("S");//to add an element in arrayList
al.add("D");//to add an element in arrayList
al.add("F");//to add an element in arrayList
System.out.println("ArrayList:");
System.out.println(al);
Object s[]=new Object[6];
s=al.toArray();//to return arrayList into array
System.out.println("Array:");
for(int i=0;i<4; i++)
{
System.out.println(s[i]);
}
}
}

Output:
ArrayList:
[A, S, D, F]
Array:
A
S
D
F

BACK

Filed in: Z-A All Java Codes

Comments are closed.