Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Want something more dynamic than an array?

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

Related Material

Java - Fundamental classes
  [42] - ()
  [1062] - ()
  [1502] - ()
  [1910] - ()
  [2323] - ()
  [2418] - ()
  [2421] - ()
  [2649] - ()
  [2734] - ()
  [2920] - ()
  [3048] - ()
  [4330] - ()
  [4396] - ()
  [4421] - ()
  [4431] - ()

C and C based languages - Memory Management
  [1497] - ()
  [1581] - ()
  [1589] - ()
  [1670] - ()
  [1845] - ()
  [2669] - ()
  [2848] - ()
  [3118] - ()
  [3144] - ()
  [3386] - ()
  [3416] - ()
  [4128] - ()
  [4340] - ()
  [4634] - ()
  [4635] - ()

resource index - Deployment
Solutions centre home page

You'll find shorter technical items at The Horse's Mouth and delegate's questions answered at the Opentalk forum.

At Well House Consultants, we provide training courses on 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.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/solutions/general- ... array.html • PAGE BUILT: Wed Mar 28 07:47:11 2012 • BUILD SYSTEM: wizard