UNIT 5 Flashcards

1
Q

Can you have multiple types of data in an array?

A

No, an array has to be the same datatype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the index of the first value in the array?

A

0, this is because arrays in java use ZERO-BASE INDEXING

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What syntax would you use to declare an int array

A

int [] intArray;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you instantiate an int array?

A

int [] intArray = new int[20];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When an array is created what data will be in the array

A

Java will populate the data with default values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How would you get the size of an array

A

nameOfArray.length

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you get the size of an ArrayList

A

arrayListReference.size();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the structure for an enhanced for loop

A

for(dataValueType variableName: dataStructureName) {
}

ex:

for(String name:groupList) {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In which cases can you not use an enhanced for loop

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly