Week 11 Part 3 Flashcards
o Arrays of [char, byte, short, int, long, float, double] have every element initialized to _ by default, array elements of Boolean type will be _____, and an array of reference type will have every element set to ____
0, false, null
o What will every single element value be in this freshly initialized array?
private int[] numbers = new int[42]
All elements are 0
o What are yetMoreNumbers element values?
o Int[] otherNumbers = new int [42]
double[] yetMoreNumbers = null
yetMoreNumbers = new double[42]
All are 0
o Why would you ever defer instantiation of an array (sometimes just to a separate line)?
You do not yet know how large to make the array
o By using an Array ___________ ____when creating an Array we can specify what each element contains
Initializer list
o char[] letterGrades = { ‘A’, ‘B’, ‘C’, ‘D’ ‘F’ }; What will the size of this array be? What will be the index of the letter A?
Size 5, A will be 0
o T/F – You can place the Array reference variable declaration and the Initializer list on different lines
False
o Initializer lists are best suited to short arrays, _____ are better suited for larger arrays
Loops
o If you specify an index below zero or one that exceeds the maximum length
ArrayIndexOutOfBoundsException
o ___ loops are best for arrays
For
o Identify this
For (int grade : letterGrades) {
System.out.println( grade );
Enhanced for loop
o This loop figures out where to start and where to stop
Enhanced for loop
o Limitation of the advanced for loop
It’s read-only, no exceptions