UNIT 5 Flashcards
Can you have multiple types of data in an array?
No, an array has to be the same datatype
What is the index of the first value in the array?
0, this is because arrays in java use ZERO-BASE INDEXING
What syntax would you use to declare an int array
int [] intArray;
How would you instantiate an int array?
int [] intArray = new int[20];
When an array is created what data will be in the array
Java will populate the data with default values
How would you get the size of an array
nameOfArray.length
How would you get the size of an ArrayList
arrayListReference.size();
What is the structure for an enhanced for loop
for(dataValueType variableName: dataStructureName) {
}
ex:
for(String name:groupList) {
}
In which cases can you not use an enhanced for loop
- if you need to change the contents of an element
- If you need to traverse the elements in a reverse order
- If you need to access only some, not all of the elements
- If you need to access more than one array or arrayList at a time inside the loop
- If you need to refer to the index number of a particular element