Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList.toArray( )

 
ricky ray
Greenhorn
Posts: 8
  • 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
  • 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
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic