Lucky Cat Tutoring Services


Arrays 01
November 3, 2009, 4:44 pm
Filed under: Class Notes, Java | Tags: , , , , , , ,

ARRAYS ARE:
–Primitive variables are designs to hold only one value at a time
–allows to create collection of like indexed values
–can store any type of data but only one type at a time
–List of data elements

Creating Arrays
–An array is an object so it needs to be referenced. Then create array and assign address

int[]nameofarray=new int [INTEGER VALUE]

Integer value can be a variable, a constant etc but always must be INT.
–Whatever data type is stored in the array determines how it is initialized. If it’s created as an INT all values start at 0.
–may be of any type (floats, car, long, double etc)

ARRAY SIZE: must be a non negative number. It may be a literal, a constant, or avariable
ex: final int ARRAY_SIZE=6
int[] numbers=new int[ARRAY_SIZE]
–Once created the size is fixed and cannot change!!

USING INDEX VALUES
–The first element is ALWAYS INDEX 0. The last element in the array is always the size or length -1

In an array with 6 indexes. The first one is index0, the last one is index5

Calling an index:
arrayname[indexnumber]= new value //assigning variables to be held in the index
arrayname[0]=17

An array is accessed by:
–The reference name
–the subscript [] which declares what to access

Can be treated like any other variable of the same type.
Continue reading



Free Programming Reference Cards
October 8, 2009, 3:50 pm
Filed under: Java | Tags: , , , ,

Programmer Ref Cards from Dzone. Free Sparknotes style cheat sheet references for programmers and students. Registration to the site is free too!