Arrays Flashcards

1
Q

What is an array

A

a data structure

a sequence of things all collected together

it is the most basic type of ‘list’

Lists of Primitives and Objects are slightly different

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

What would be the syntax to create an int array called ‘myIntArray’of 6 values long?

A

int[] myIntArray = new int[6];

= 0 0 0 0 0 0
(currently all values in the array are 0)

type[] = new type[No.ofElements]

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

Is an array an object?

A

YES

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

What is myIntArray?

A

it is a reference

therefore, can have multiple references to the same array and can pass arrays to methods

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

which loop works very well with arrays?

A

FOR loops:

  • print all the elements in the array
  • set the elements in the array
  • look for a particular element in an array
  • sort an array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does this code do?

public static void main(String[] args) {

int [] myIntArray = new int[6];
for(int i=0;
i

A

It sets the 2nd position

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

What is an interface?

A

it defines a set of methods

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

If a class implements an interface, it must implement…?

A

the methods in the interface

e.g. The interface called Comparable includes the compareTo method

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