Collections and Generics Flashcards

1
Q

What is a collection?

A

An object that can hold other objects

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

What a set?

A

collection that is unordered

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

What is a list?

A

collection that is ordered in some way, and doesnt require that its elements be unique

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

Whats a Map?

A

Elements in the collections have key, value pairs

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

T/F: Collections store objects, and cannot store primitive types?

A

True. Wrapper classes must be used for primitive types

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

Common collection classes

A

pic

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

Whats an arraylist compared to an array?

A

its size can be expanded and efficient for accessing elements randomly

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

whats a linkedlist

A

similar to arraylist but with more features. Its elements are linked to other elements.

To add or remove, just

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

whats a hashmap?

A

stores object with key-value pairs

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

whats a treemap?

A

stores objects having key-value pairs in a special tree structure

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

What are generics?

A

class type that takes the data types as parameters. Makes it closer to dynamically typed language

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

Explain arrayList constructors

ArrayList<Type>()
ArrayList<Type>( int n)
ArrayList<Type>(Collection obj)</Type></Type></Type>

A

Defaults to size 10

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

ArrayList methods

A

Lot more functionality than array

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

linkedlist

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

Whats the difference in adding element to top of LinkedList vs ArrayList?

A

ArrayList stored in contiguous elements so adding to top, bumps all down one.

LinkedList just changes reference of the top…. not totally sure but its more efficient

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

HashMap vs TreeMap?

A

HashMap not stored in any sequence. TreeMap stored by Key, Value

17
Q

common hashmap and treemap methods

A
18
Q

How to retrieve hashmap objects?

A

HashMap objects implement the Map.Entry interface, its a Map.Entry data type

19
Q
A