Arrays - Day 3 Flashcards
Initialising the array
Datatype[] arrayVarName = {elem1e,elem2};
Datatype[] arrayVarName = new dataType[size];
Locating array index
Arrayvarname[index]
Arrays are objects?
Yes
Unlike python, arrays are pretty restricted and can only hold 1 data type
True
For loop in array for elements
For (int index = 0; index < arrayName.length; index++) {
}
For each loops
Splits up each element, no use of indexing
For(dataType variableName: arrayName){
}
Multi dimensional arrays
Each element of the array holding other arrays.
For a 2D array:
Datatype[][] arrayVarName = new dataType[rowsize][columnsize];
Row is length of array
Column is array of each array element
Columnsize is optional
When a value isn’t initialised in an array. What happens
It saves the value as zero/defaults.
Command line arguments
Inputs passed into the program through the command line
How to use command line
Need the parameter
“String[] args” in the main
Input through command line example
System.out.printIn(“hello” +args[0]):
NOT TESTED for exam. WILL USE SCANNER