You are on page 1of 6

1

Array Technical Document

Introduction
An array is a collection of variables of the same type. Each of the
variables in an array are referred to as elements and each of these
elements can be accessed by its index. Arrays can be
multidimensional, which means that arrays can form matrixes cubes
and more. Arrays are useful when sorting many elements of the same
data type and searching through them.

How Arrays are used


Arrays are declared by, writing the data type followed by [] and then
the name of the array. The format for declaring and array is: arrayType
[] arrayName

All of the elements in an array can be accessed by its index. The first
element will be located in the index 0 and the second element would
be located in the index 1. Arrays are created in the format: arrayName
= new arrayType[arraySize]. In the figure below the integer array
intArray is being declared and it contains 3 elements. The element at
the index 2 is being assigned
to the integer 32.
2

Printing and Processing Arrays


Arrays are often processed using for loops because all of the elements
are of the same data type and the size of the array is known. The

figure below shows a loop that stores the numbers from 1 to 3 in a


three element integer array.

Loops are also useful to print the elements of an array. In order to print

a specific element, you would need to know the index of that element.
The figure below shows a loop that would print out the elements of the
integer array from above.

Sorting and Searching Arrays


In order to search for a particular element in an array, sorting the array
would be helpful. Arrays can be sorted many different algorithms. One
method of sorting is the bubble sort, which sorts numbers in ascending
order. A bubble sort performs a loop to checks if the number at a
certain index is larger than the one ahead of it. This is performed for
each of the numbers in the array, then repeated until all of the
elements are in ascending order. The figure below is a bubble sort.
3
4

A binary search is used to find the index of an element in an array. In


order for the search to work, the array must be in either ascending or
descending order. A binary search first finds the middle element, and
checks if it is the target element. If it is not, the search checks if the
target is larger or smaller than the middle element in order to split the
number of possibilities in half. The algorithm continues to split the

numbers in half until the middle element matches the target.

Multidimensional Arrays
Multidimensional arrays are arrays two, three, or more dimensions. Two
dimensional arrays can be represented as matrixes. A two dimensional
array can be displayed as a table on paper, with rows and columns.
The format for a two dimensional array is: arrayName[rowIndex]
[columnIndex]. A three
dimensional array would
be the same but with a
third [index]. The figure
below shows a two dimensional integer array.
5

Array Representation in Memory


In Java a multidimensional array is just a one dimensional array of
references to one dimensional arrays. Each of these one dimensional
arrays gets its own block within memory. The elements of an array
occupy consecutive memory locations.

Conclusion
Arrays are extremely useful in sorting and searching through large
amounts of data. A bubble sort can be used to sort number arrays in
ascending order and a binary search can be used to find the location of
an element within that array. Arrays can have multiple dimensions
which are basically one dimensional arrays that reference to other one
dimensional arrays. Each of these arrays gets its own block of memory.
Loops are mainly used when processing and printing arrays. Arrays
make it easy to hold large amounts of data and sort through them.

Works Cited

Cheung, Shun. Array of char in memory. Digital image. Emory University. Emory
University, n.d. Web. 27 Nov. 2016.
6

You might also like