wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes ArrayList.toArray( ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "ArrayList.toArray( )" Watch "ArrayList.toArray( )" New topic
Author

ArrayList.toArray( )

ricky ray
Greenhorn

Joined: Sep 04, 2007
Posts: 8
I am getting ClassCastException when I do following
ArrayList method1();
String [] stringArray = (String[])method1.toArray();
Please help.
desmond mongwe
Greenhorn

Joined: Oct 11, 2000
Posts: 7
hi
I got that exception as well. I suggest you simple do
Object o[]=Arralist.toArray();
and then try converting to Strings later.
by calling toString(); cheers
Tinyiko


<A HREF="mailto:mpisi@mailbox.co.za" rel="nofollow">mpisi@mailbox.co.za</A>
scott irwin
Ranch Hand

Joined: Aug 07, 2000
Posts: 87
This is a bit better.
(String[])stringArray.toArray(new String[stringArray.size()]);
You are creating an array of the correct type and ArryList fills the provided array and returns it.
Suresh Bansal
Ranch Hand

Joined: Jul 23, 2001
Posts: 91
Thanks ...


Journey is as important as the Destination.<br /> <br />PMP, SCJP, SCJD, SCEA (Part 1), SCMAD, SCDJWS
 
jQuery in Action, 2nd edition
 
subject: ArrayList.toArray( )