Sure, that's easy.  In fact, I just wrote a few dozen of these little
statements.


// Long version
int size = v.size();
BobObj[] objs = new BobObj[size];
v.copyInto(objs);

// Short version
BobObj[] objs = new BobObj[v.size()];
v.copyInto(objs);

Arrays are of type object, so you can even cast them, but this can be error
prone.

    // Ok
    Object[] newArray = new String[]{"one","two","tree"};
    String[] stringArray = (String[])newArray;

    //Wrong!!!
    Object[] newArray = new Object[]{"one","two","tree"};
    String[] stringArray = (String[])newArray;

Other useful array things.
    System.arrayCopy(...see javadoc...);

Or, how about when you have an array, but you really need a Vector.
    Vector v = new Vector(Arrays.asList(stringArray));


Have fun.

David Blevins
---
OpenEJB - EJB Container System
www.openejb.org
ftp.exolab.org/pub/openejb/




> -----Original Message-----
> From: tclug-devel-admin at mn-linux.org
> [mailto:tclug-devel-admin at mn-linux.org]On Behalf Of Bob Tanner
> Sent: Tuesday, October 30, 2001 3:07 PM
> To: tclug-devel at lists.real-time.com
> Subject: [TCLUG-DEVEL] Vector of Objects to Array of Objects?
>
>
> Is there a simple way to convert a Vector of Object to and Array
> of Objects of
> the same type?
>
> What I'm doing now is something like this:
>
> Vector v = new Vector();
>
> <snip>
>    v.add(obj)
> <snip>
>
> // Ok, vector has a bunch of Object in it
>
> int size = v.size();
> BobObj obj = new BobObj[size];
>
> for (int i = 0; i < size; i++) {
>   // Walk the vector making it into an Array
>   obj[i] = new BobObj(result.get(i));
> }
>
> I look at the Vector.toArray() thinking that would solve my
> problem, but I can't
> seem to get it to work.
>
>
> --
> Bob Tanner <tanner at real-time.com>         | Phone : (952)943-8700
> http://www.mn-linux.org, Minnesota, Linux | Fax   : (952)943-8500
> Key fingerprint =  6C E9 51 4F D5 3E 4C 66 62 A9 10 E5 35 85 39 D9
>
> _______________________________________________
> tclug-devel mailing list
> tclug-devel at mn-linux.org
> https://mailman.mn-linux.org/mailman/listinfo/tclug-devel