Java Collections Flashcards
What is a collection?
An object that groups multiple elements into a single unit.
Poker hand: collection of cards
Mail folder: collection of letters.
Collection vs Map
Collection - a group of objects known as elements
public interface Collection
Map - a group of objects where each object maps keys to values
public interface Map
How do you iterate over a collection
For-each notation,
need an iterator object if you want to safely remove elements while iterating.
What is the Set interface?
Extends collection, a set contains no duplicate elements. 2 sets are equal if they contain the same elements even if the containers are different.
What is the List interface?
A list is an ordered collection of elements that may contain duplicate elements. Two lists are treated equal if they contain the same elements in the same order.
Concrete List implementation in Java
ArrayList
LinkedList
What is a Queue interface?
Collection of elements stored for processing first in first out.
What is a map interface?
2 generic type arguments where keys are mapped to value each key maps to at most one value.