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
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7Knm6IpUti5zAV8EFEGCcRQ2LhUM8KbDEeORs-Ntr-dhUkku18O4UbY55sF8S72e5ueIPiYDnLG5UTDHwE6CizLz53xQMnlD59hJ_4wVWxWoAbtoI-gzQPJG0JBQh6Q1drZ1kOwSl4rFk/s320/mod1.png)
we're gonna declare :
double [] firstDblArray, secondDblArray ;
firstDblArray = new double[50000] ; ( it creates a reference )
secondDblArray = firstDblArray ;
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuYpab4qRke1Q5mvqM8gOrRmA5qpkWL3ygPh2FiiePeyEkRAQr_QKwKw_XxRzb6XXE0X93iBi4cG39tdGQ3p7esxsyO4k-SZRp9ZyJIHjqTlqWigymwviIBXNF4K9htYRznFmVTrP6uND3/s320/mod2.png)
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
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