> Vector<String []> vector = aFunction();
>
[quoted text clipped - 35 lines]
>
> Any help will be appreciated!
This code won't compile. Here's how you can fix it:
<code>
import java.util.Vector;
public class Test {
public static void main(String[] args) {
Vector<String[]> vector = aFunction();
String[] stringArray;
for (int i = 0; i < vector.size(); i++)
stringArray = (String[])vector.get(i);
}
public static Vector<String[]> aFunction() {
Vector<String[]> v = new Vector<String[]>();
String[] sa = new String[10];
int j = 0;
while (j < 10) {
sa[0] = "zero";
sa[1] = "one";
// ...
sa[9] = "nine";
v.add(sa);
j++;
}
return v;
}
}
</code>
this runs without error.
- Oliver
Ralf Seitner - 30 Aug 2006 18:44 GMT
Oliver Wong schrieb:
>> Vector<String []> vector = aFunction();
>>
[quoted text clipped - 72 lines]
>
> - Oliver
Hi!
OK. I just wanted to send an answer, but Oliver was quicker than me...
Just one thing, I want to add. You do not have to cast explicitly to
String[], because your vector only contains String[], due to the
declaration Vector<String[]>vector.
bye, Ralf
> Vector<String []> vector = aFunction();
>
> String[] stringArray;
> for (i = 0; i < vector.size(); i++)
> stringArray = (String[])vector.get(i);
Forgetting for the moment that the above code is without context...not
in any class, method, etc...you could make some improvements to the
loop. One thing is that there's no need to cast your "vector.get" to a
String[] since it was explicitly created to contain only such. But then
you can use the improved for loop that comes in 1.5, like this:
for (String[] stringArray : vector) {
// do something here with the current stringArray
}
> public Vector<String []> aFunction() {
> Vector<String []> v = new Vector<String []>Vector();
[quoted text clipped - 29 lines]
>
> Any help will be appreciated!
That last part is a little unclear...how could it compile? What is new
"Vector<String []>Vector();" supposed to mean?
And a ClassCastException should be accompanied by a stack trace that
could show you the exact line where it originates. But since the above
is fragmented and cannot be compiled as presented, it's not clear what
your problem might be.

Signature
Steve W. Jackson
Montgomery, Alabama
RC - 30 Aug 2006 19:56 GMT
> That last part is a little unclear...how could it compile? What is new
> "Vector<String []>Vector();" supposed to mean?
Sorry, that is typo error. It should be
Vector<String []> v = new Vector<String []>();
Chris Smith - 31 Aug 2006 05:14 GMT
> > That last part is a little unclear...how could it compile? What is new
> > "Vector<String []>Vector();" supposed to mean?
>
> Sorry, that is typo error. It should be
>
> Vector<String []> v = new Vector<String []>();
Just out of curiosity, did you actually retype all of your code into
your news client? If so, wow. That is not only bad for us, since
you're bound to produce typos, but it must also be a real pain for you
as well! Copy and paste really is much easier.

Signature
Chris Smith