double a = 10.0;
or,
Point p1 = new Point();
But what if we want to read in a big datafile?
type arrayName[];
or,
type[] arrayName;
double xCoords[];
double []xCoords;
Point pathway[];
arrayName = new type[size];
e.g.,
xCoords = new double[10];
pathway = new Point[10];
double xCoords[] = new double [10];
xCoords[0] = 100.0;
pathway[9] = somePoint;
myX = xCoords[0];
Gives myX as 100.0.
myX = pathway[9].x
int : 0
double : 0.0
char : spaces
boolean : false
null
.
Point[] pathway = new Point[10];
pathway[0] = new Point();
System.out.println(pathway[0].x);
System.out.println(pathway[1].x);
double xCoords[] =
{10.0,0.0,1.0,1.0,2.0,3.0,5.0,8.0,1.0,2.0};
Point pathway[] = {p1, new Point(), p2};
name.length
e.g.
System.out.println(xCoords.length);
int xCoords[] = new int[10];
xCoords.length
int popMap[][] = new int[100][100];
arrayName[10][1]
(value at the 11th row, 2nd column)
int array2D[][] = new int [4][];
array2D[0] = new int[3];
array2D[1] = new int[3];
array2D[2] = new int[3];
array2D[3] = new int[3];
int array2Dirreg[][] = new int [4][];
array2Dirreg[0] = new int[1];
array2Dirreg[1] = new int[3];
array2Dirreg[2] = new int[2];
array2Dirreg[3] = new int[3];
int array3D[][][] = new int[100][][];
double array2D[][] =
{
{1.0,0.0},{1.0,1.0},{2.0,3.0},{5.0,8.0},{1.0,2.0}
};
double array2Dirreg[][] =
{{1.0},{1.0,1.0,1.2},{2.0,3.0},{5.0,8.0,1.0}};
name.length
name[positionInFirstDimension].length
array2Dirreg.length // is 4
array2Dirreg[0].length // is 1
array2Dirreg[4].length // is 3
Making a variable is a two-stage process.
Make the name:
Assign it to a value:
Or all in one go:
|
Making an array is a three-stage process.
Make the name:
Assign it to spaces
Or all in one go:
Then assign values:
|