aspose file tools
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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "ArrayList.toArray( )" Watch "ArrayList.toArray( )" New topic

ArrayList.toArray( )

ricky ray

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

Joined: Oct 11, 2000
Posts: 7
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

<A HREF="" rel="nofollow"></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
Have you tried LearnNowOnline?
subject: ArrayList.toArray( )