Results 1 to 8 of 8

Thread: Stupidly simple: Java arrays

  1. #1

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935

    Stupidly simple: Java arrays

    How do you nondestructively resize an array in Java? All the Sun tutorial taught me was how to get the number of elements with .length.

  2. #2
    Lively Member
    Join Date
    Feb 2001
    Location
    Jutland, Denmark
    Posts
    71
    You can't resize an array in java.
    You have to make a new array an copy the first array to this,
    or some thing like this.
    Normaly I double the array every time I need to "Resize" my array
    Some plase I have a Class for this.
    I will try to find it if you like.

  3. #3

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    Nah, that's alright, I'll just use the Vector class I suppose.

  4. #4

  5. #5
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    have you tried doing a an arraycopy into from array A to B (where B is a larger array) and then A = B? might work...
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  6. #6

    Thread Starter
    Member filburt1's Avatar
    Join Date
    Aug 1999
    Posts
    6,935
    Sounds kinda processor-intensive because I'm in a for-loop and in each iteration increasing the size of the array.

  7. #7
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332

    Cool

    LoL! oops... retreat! run for the hills! retreat!
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  8. #8
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Filbert couldn't you just use a List or a Set
    (depending if you want you elements ordered or unordered)
    and use the asList() method defined in the java.util.Arrays
    class and the toArray() method defined in the Collection interface?

Posting Permissions

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



Click Here to Expand Forum to Full Width