Arrays Flashcards
What is an array
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
What would be the syntax to create an int array called ‘myIntArray’of 6 values long?
int[] myIntArray = new int[6];
= 0 0 0 0 0 0
(currently all values in the array are 0)
type[] = new type[No.ofElements]
Is an array an object?
YES
What is myIntArray?
it is a reference
therefore, can have multiple references to the same array and can pass arrays to methods
which loop works very well with arrays?
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
What does this code do?
public static void main(String[] args) {
int [] myIntArray = new int[6];
for(int i=0;
i
It sets the 2nd position
What is an interface?
it defines a set of methods
If a class implements an interface, it must implement…?
the methods in the interface
e.g. The interface called Comparable includes the compareTo method