Wednesday, May 25, 2011

May 25th - 2011





An array is many instances of a single data type: 37 char, or 352 doubles.

To declare an array:
double[] arrayofDouble = new double[25];
to declare one variable:
double oneDouble ;



the size of an arrat need not be known until runtime

int k ;
k = Integer.valueOf(args[0]);
double[] arrayofDouble = new double[k];



public static main (string [] args) { }


reminder :

double firstDblval, secondDblval ; firstdblval = 42.0; secondDblval = firstDblVal

------------
we're gonna declare :

double [] firstDblArray, secondDblArray ;
firstDblArray = new double[50000] ; ( it creates a reference )
secondDblArray = firstDblArray ;


secondDblArray[42] = 357.8 ;
if (firstDblArray[42] == 357.8)
System.out.println ("True") ;


Will print True !

When we write

if (firstDblArray == secondDblArray) {




}

What is being checked?

It is checking if the value of firstDblArray is the same as secondDblArray, not the content.

-------------


Arrays are a derived class of Object.


When i really want a separate copy of an array, I can clone it.

double[] dblArr1 = new double [50000];
double[] dblArr2 ;
dblArr2 = dblArr1.clone() ;

creates an entirely separate block of space for dblArr2, initialized to the contents of the block of space holding the 50,000 entries of dblArr1

------------
1:14 PM

What if i need a reference to a single value of a basic type ?
-could use double [] trivial = new double[x]

- "Autoboxing" is another way to create a reference to a basic type. for each basic type, a matchin class:

char ===> Character
boolean ==> Boolean
.
.
int ====> Integer

No comments:

Post a Comment