Week 5 - Collections Flashcards

1
Q

Static data structures…

A

…are collections of data of a fixed size when a program is compiled.

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

Dynamic data structures are…

A

…variable in size & structure (ie an arraylist)

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

Collections are primarily defined through…

A

A set of interfaces

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

What collection cannot contain duplicate elements?

A

A Set

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

What collection does allow duplicate elements?

A

Lists

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

Data structures store and access data in different ways? True or false?

A

True

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

What do ArrayLists() store?

A

Object references

They differ from arrays as arrays store primitive data

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

An ArrayList() has a fixed number of items? True or false?

A

False.

Normal Arrays have fixed items declared at the beginning. ArrayLists can automatically increase.

The size of an arraylist object is the current number of items stored

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

After importing the Java.util.ArrayList package how are ArrayLists declared?

A

ArrayList myArray = new ArrayList();

myArray.add(“San”);
myArray.add(“Saint”);

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

Only objects can be added to a collection. True or false?

A

True.

public void add (Object element) - the signature for the ArrayList add method

To add primitive you need a wrapper class:

myList.add(new Integer(5)); // wrap

Integer num = (Integer)myList.get(0); // unwrap

Int n = num.intValue();

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

Which sets implement the Set interface?

A

TreeSet (binary tree, stores in order) and HashSet (no ordering of elements)

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

A hash map implements what interface

A

The map interface

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

True or false, a hashmap is a collection of key-value pairs?

A

True.
For example a phone directory “John Smith”, “0162347272”.

Each entry has a name-number association

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

What if statement would a hashmap use to check if a hashmap contained “Andrew”

A

if(.containsKey(“Andrew”

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

How do we add a value to an ArrayList?

A

ArrayList insects = new ArrayList();

insects.add(“horsefly”)

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