• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

vector to String

 
Maria Krishna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
when i converted a vector to a string array using toArray, i had a classCastException, How do I convert a vector to String object
thanks in advance
Maria
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as you are assured that every element in the vector is a String, try this:

The "toArray()" method in Vector is overloaded; if you don't call the correct one it will only return an array of Object. If you want to cast it to some other type, you have to pass in a "seed" array of that type. As shown in this example, it can have a length of zero.
[ November 07, 2003: Message edited by: Wayne L Johnson ]
 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, if you are not assured that every object is a String, you will have to iterate through the Vector and invoke toString() on each of the Vector's elements (adapting the previous example):
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic