Most traditional programming languages include support for "arrays", in which the program can store a whole series of pieces of information in the same type. For fast access, the elements of an array are usually held in successive memory locations, and each element takes the same amount of storage.
With languages such as C, the number of elements in an array (its dimension) was defined at compile time, and was then fixed in the executable program file. This created a problem if the programmer didn't know what the maximum size would be, and a number of mechanisms such as "malloc" were added to allow what was in effect an array to be defined while the program ran.
By contrast to C, the Java language has a dynamic memory allocation model, so arrays can be dimensioned at run time. You can write a program that works out how big an array needs to be and THEN dimension it to allocate the memory. Alas, once an array is dimensioned even in Java you can't come back later and simply extend it - after all, there's probably something else in the computer's memory directly after the end of your array by this time.
Java supports a number of collection types (via standard classes) that let you define structures to hold a whole series of objects, even if you don't know how many objects you'll want to hold in your structure. Vectors (or also ArrayLists in Java 2) can hold as many objects as you like, and you don't have to tell Java how many. The information isn't stored sequentially in memory, so their use isn't as efficient as an array, and they're not a part of the base Java language so you have to access them through an object syntax, but they do solve the problems of changing an array size even after it has some data stored in it!
You can go a stage further too. Array elements are traditionally numbered (indexed) from 0 or 1 up - that's fine for many uses, but there are often times you would prefer to give each element a unique name. Java's standard HashTable class (also a HashMap from Java 2) give you this ability, though it brings in a whole series of new considerations too if you need to be able to iterate through all the elements in such a collection.
If you're not a Java writer ...
Perl's "lists" are the equivalent of a Vector in Java, and "hashes" are the equivalent of a HashTable - Perl doesn't actually use arrays even though the word used to be mistakenly used to describe both lists and hashes.
In Tcl, an "array" is the equivalent of a HashTable in Java. As all data in Tcl is held in strings, there is no equivalent to an array or a Vector in Java - elements simply can't be counted like that.
PHP arrays can be treated as either HashTables or as Vectors - they can always be dynamically extended, and you can reference then by number (position) or by text key as you wish.
See also Java Utility Classes
Please note that articles in this section of our
web site were current and correct to the best of our ability when published,
but by the nature of our business may go out of date quite quickly. The
quoting of a price, contract term or any other information in this area of
our website is NOT an offer to supply now on those terms - please check
back via our main web site
Java - Fundamental classes 
Java - factory method, encapsulation, hashmap example - (2014-11-27) 
String handling - from first steps to practical examples - (2010-11-13) 
Sorting - naturally, or into a different order - (2010-08-14) 
for and foreach in Java - (2010-04-22) 
Length, size or capacity in Java? - (2010-02-24) 
Sorting Collections of Objects in Java - (2009-09-25) 
Viv.java uses unchecked or unsafe operations - explanation and cure - (2009-09-24) 
Java Collection Objects in the java.util package - (2009-08-05) 
Java - Generics - (2008-11-27) 
Java, sorting, ArrayList example, generics - (2008-01-11) 
Java sorting - comparable v comparator - (2007-02-02) 
Do languages change? - (2004-09-08)C and C based languages - Memory Management 
Simple C structs - building up to full, dynamic example - (2014-12-03) 
Allocating memory dynamically in a static language like C - (2013-06-30) 
Storing Tcl source code encoded, and running via your own C program - (2011-09-02) 
Adding the pieces together to make a complete language - C - (2011-08-11) 
Setting up arrays in C - fixed size at compile time, or dynamic - (2011-01-24) 
Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02) 
C course - final course example puts it all together - (2010-07-02) 
Efficient use of dynamic memory - C and realloc - (2010-03-10) 
Passing a table from Lua into C - (2008-10-18) 
Dynamic Memory Allocation in C - (2008-06-09) 
Dynamic Memory Allocation in C - calloc, realloc - (2008-03-22) 
What is an lvalue? (Perl, C) - (2008-03-18) 
Training Season Starts again! - (2008-01-07)resource index - Deployment
Solutions centre home page
You'll find shorter technical items at
The Horse's Mouth
delegate's questions answered at
At Well House Consultants, we provide
subjects such as Ruby, Lua, Perl, Python, Linux, C, C++,
Tcl/Tk, Tomcat, PHP and MySQL. We're asked (and answer)
many questions, and answers to those which are of general
interest are published in this area of our site.