An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by one (single dimensional array, or vector) or multiple indexes.
An array is an ordered data structure consisting of a collection of elements (values or variables), each identified by at least one index, stored in contiguous memory locations. An array is typically stored so that the position of each element can be computed from its index tuple by a mathematical formula. In some languages (C, Java, etc.) the length of the array must be set beforehand. In other languages (Ruby, Python, LISP, etc.) the length of the array grows dynamically as elements are added.
Elements of an array are generally specified with a 0-first index, for example,
myarraywould represent the first element of
lis the length of the array minus 1) would represent the last element in the array. However, some languages such as old Fortran and Lua use 1 as the initial index.
Some languages (c++, java, c#) have "basic arrays" and collections. Basic arrays are supported by the compiler directly; have fixed size and only provide element access by index. Collections, like Java's arraylist, are system library classes implemented on the top of these basic arrays and have a wide range of various methods. In such cases the tag
arraysshould be used to name the simple arrays.
Arrays can be statically allocated or dynamically allocated. The way in which you access the array and its type varies based on how it is declared and allocated.
Array in specific languages
In ruby the normal array class is called an
In php arrays are implemented as ordered maps which may contain a mix of numeric or string keys.
When tagging a question with this tag, also tag the question with the programming language being used.