Collections Flashcards

1
Q

What is an iterator?

A

Use it to cycle through elements in collection. Each collection class provides an iterator() method.

Iterator itr = myList.iterator();
While(itr.hasNext()){
Object e = itr.next();
}

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

What are comparable and comparator?

A

Comparable implemented by class, overrides compareTo(T t). Used by calling compares to.”

Comparator requires extra comparator class created that implements comparator. Overrides compare(a, b). Used by Collections.sort(list, new comparator());

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

Types of collections?

A

List, Set and Map. List include ArrayList, LinkedList, Vector. Map includes HashMap, TreeMap. Set includes HashSet and TreeSet.

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

Some basic List methods?

A

add()
Size()
Remove()
Clear()

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