File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList.toArray( )

 
ricky ray
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting ClassCastException when I do following
ArrayList method1();
String [] stringArray = (String[])method1.toArray();
Please help.
 
desmond mongwe
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
scott irwin
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic