dynamic arrays

I'm new to programming in Java and did some stuff in PHP up to now. PHP handles arrays quite liberally. You never have to tell the finite size of the array and can add new members at any time.

Now I tried to work with arrays in Java and found the following. Even though Java doesn't require you to tell it the exact size of the array at compile time you have to tell it at run time before using the array. Once you specified the size of the array there's no way to make it larger. However there are cases when you can actually never know exactly how large an array needs to be.

My questions are now:

Is my observation true?

If so, is there any way, like a wrapper class or something, that works around that limitation?

If there isn't one out there yet and anybody else would need it, I'll be glad to give my solution away as I just developed one...

[890 byte] By [mimaroxa] at [2007-10-2 3:56:20]
# 1
> Is my observation true?Yes> If so, is there any way, like a wrapper class or> something, that works around that limitation?Yes. See ArrayList and Vector in the java.util package
tjacobs01a at 2007-7-15 23:17:41 > top of Java-index,Java Essentials,Java Programming...
# 2

Yes, arrays in Java can't be resized. Usually the collection Framework takes over most of the work done by arrays in other languages, it provides exactly what you want.

Check java.util.Collection, Set, List, Map, ... a java.util.List is what comes closest from what you expect from an array, according to your definition. The most common implementation is ArrayList (but there are other implementations as well, such as LinkedList).

Google for java collection tutorial for more information.

JoachimSauera at 2007-7-15 23:17:41 > top of Java-index,Java Essentials,Java Programming...