Personal tools
You are here: Home Members mpate1's Home Arrays
Document Actions


by Mit Patel last modified 2006-03-27 10:00 PM

Some static things about arrays:

  1. Always always always start at index 0.
  2. Array has just one name.
  3. Array is an ordered list of values with unique numeric index.
  4. These values are known as array elements.
  5. The type of the values stored within the array has to be same.
  6. Size of array, n is indexed from 0 --> n-1.
  7. The size you define for array is fixed.
  8. Array is considered to be an object thus, array of integers, Chars and String objects can be created.
  9. When an initializer list is used you 'don't need'

    a) to specify the size of the array

    b) or use new operator

One-dimensional Array

  1. Declare an array

    int[] labscores = new int[25]

  2. Value is referenced via array name followed by index in brackets.


  3. Way to initialize and instantiate array:

    int[] labScores = {20,19,...,16,18.5,20};

    Notice the usage of brackets, comma and semi-colon.

Let us see what wonders two-dimensional arrays can do.

Two-dimensional arrays:

  1. Table of elements represented by rows and columns. No more complicated than that.
  2. Said to be array of arrays. (Don't keep repeating this otherwise you will never come out of recursive thinking).
  3. Declare a two dimensional array

    int[][] labScores = new int[4][25]

  4. Value is referenced using two index values


  5. Way to initialize and instantiate array:

    int[][] labScores = { {14, 20, 28, 19, 20}, {17, 19.5, 20, 20, 20}};

    Notice the use of brackets, commas and semi-colon.

    Make sure the list is of the same size. If you put five elements in one then second should have the same. It is not necessary to have same # of lists as the elements. This example has two lists but the elements are five.

Mathematicians, think of this as matrix.

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: