Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2004
    Location
    Norway
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copy all vector values to a int[] - how?

    This is java....

    I have a vector, myvector.
    I want all values in this vector to be put inside a int[].
    How?
    I have tried this, but it doesn't work:
    int[] tmp = myvector.toArray( new int[myvector.size()]);

    Gives me this error:
    The method toArray() in the type Vector is not applicable for the arguments (int[])

    ANyone have a idea?

    Rune

  • #2
    Regular Coder
    Join Date
    Dec 2003
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A vector holds Objects so you won't be able to get ints from it, only Integers (assuming that's what you put into it). The syntax would be something like:
    Code:
    Integer[] tmp = (Integer[])myvector.toArray();
    shmoove


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •