3:06 pm - Wednesday September 26, 2992

LinkedList Example Program for toArray(T[] a)

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

//program name: LinkedList Example Program for toArray(T[] a)
/**
@ author:candidjava.com
@description: Returns an array containing all of the elements in this list in proper sequence (from first to last element);
the runtime type of the returned array is that of the specified array.
*/
import java.util.*;
public class LinkedlistEx {
public static void main(String args[])
{
try
{
LinkedList<String> a =new LinkedList<String>();//create object for linkedlist
a.add("a");
a.add("f");//add elements.
a.add("d");
a.add("s");
System.out.println("elements in the list"+a);
String []Arr=a.toArray(new String[0]);//this method converts list to string array type.
System.out.println("after converting list to string");
for (int j=0;j<=Arr.length;j++)
{
System.out.println(Arr[j]);
}
}
catch(Exception ae)
{
}
}
}

Output:
elements in the list[a, f, d, s]
after converting list to string
a
f
d
s

BACK

Filed in: Z-A All Java Codes

Comments are closed.