aspose file tools*
The moose likes Java in General and the fly likes Vector.toArray(object [] a) ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Vector.toArray(object [] a) ?" Watch "Vector.toArray(object [] a) ?" New topic
Author

Vector.toArray(object [] a) ?

Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
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 ]

Younes
By constantly trying one ends up succeeding. Thus: the more one fails the more one has a chance to succeed.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
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


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Weerawit Maneepongsawat
Ranch Hand

Joined: Apr 11, 2002
Posts: 203

may be like this..i holp this help.


Weerawit<br />SCJP 1.4, SCWCD 1.2, SCWCD 1.4, SCBCD 1.3, SCBCD 5.0, SCMAD 1.0, SCJA 1.0, SCDJWS, SCJD, SCEA, SCDJWS 1.5
Younes Essouabni
Ranch Hand

Joined: Jan 13, 2002
Posts: 479
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector.toArray(object [] a) ?