Lec 8: Arrays Flashcards
Syntax for declaring an array
datatype[] arrayRefVar;
Syntax for declaring an array of a specific size
dataType[] arrayRefVar = new dataType[arraySize];
ex: double[] myList = new double[10];
Syntax for getting the length of an array
array.length
What is the default value of a bool if not preset
false
what is the default value of a char if not preset
‘\u0000’
it is an invisible character
syntax for creating an array with specific double elements
double[] myList = new double[4]
myList[0] = 1.9;
myList[1] = 2.1;
or
double[] myList = {1.9, 2.9, 3.4, 3.5};
What is the syntax for a foreach loop that prints all the elements in an array of double values
for (double value : myList){
System.out.println(value);
}
Does list 2 = list 1 create a new list?
No, it only copied the reference to list 2
How to copy the elements of an array to another
you must copy the array’s individual elements to the other array
When passing an array to a method, what is passed to the method?
the reference of the array
What is the name of an array without an explicit reference variable?
anonymous array
True or false” For a parameter of a primitive type, the actual value is passed instead of a reference
True
True or false: Changing the value of the local parameter inside the method changes the value of the variable outside the method
false
True or false: for a parameter of an array type, the reference value is passed
True
True or false: Any changes to the array that occur inside the method body does not affect the original array that was passed as the arg
False