• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Vector.toArray(object [] a) ?

 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I have a Vector that I previously filled with String values coming from a String[][] array.
Now , I need to get back my String [][] array from the vector.
The method Vector.toArray(Object[] a) doesn't works and I don't knwo why.

This code will not work and will throw a java.lang.ArrayStoreException,
unless I uncomment the for loop and comment this line :columns=(String[])subVector.toArray(columns);
I don't understand why? Isn't it supposed to do the same?
If anybody has an idea, I would be glad to understand.
Thx in advance
[ April 03, 2003: Message edited by: Younes Essouabni ]
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Younes,
You must be passing in a subvector that has some element other a String somewhere. I tried it both ways with this:

And got this output both times:

Michael Morris
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

may be like this..i holp this help.
 
Younes Essouabni
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Michael, thank you Weerawit.
It sees that you were right, there isn't only string object.
That's the reason why this one works: columns[j]=subVector.elementAt(j).toString();
and this one doesn't works : columns[j]=(String) subVector.elementAt(j);
I thought that both were the same, but it is not. One is "translating" an object into a string, and the other is casting an object into a string, which is permitted as long as the object effectively contains a string.
Thank you for your help
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic