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();
}
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());
3
Q
Types of collections?
A
List, Set and Map. List include ArrayList, LinkedList, Vector. Map includes HashMap, TreeMap. Set includes HashSet and TreeSet.
4
Q
Some basic List methods?
A
add()
Size()
Remove()
Clear()