|
-
Dec 21st, 2001, 07:50 PM
#1
Thread Starter
Member
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.
-
Dec 22nd, 2001, 02:58 AM
#2
Lively Member
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.
-
Dec 22nd, 2001, 11:20 AM
#3
Thread Starter
Member
Nah, that's alright, I'll just use the Vector class I suppose.
-
Dec 23rd, 2001, 05:24 PM
#4
Dazed Member
-
Dec 28th, 2001, 06:05 AM
#5
Hyperactive Member
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
-
Dec 28th, 2001, 11:38 AM
#6
Thread Starter
Member
Sounds kinda processor-intensive because I'm in a for-loop and in each iteration increasing the size of the array.
-
Dec 28th, 2001, 12:46 PM
#7
Hyperactive Member
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
-
Dec 28th, 2001, 02:48 PM
#8
Dazed Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|