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.
Printable View
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.
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.
Nah, that's alright, I'll just use the Vector class I suppose. :)
This thread might help. :)
http://www.vbforums.com/showthread.php?threadid=93424
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...
Sounds kinda processor-intensive because I'm in a for-loop and in each iteration increasing the size of the array.
LoL! oops... retreat! run for the hills! retreat!
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?