Textbook Notes (290,000)
US (110,000)
Cornell (300)
CS (5)
Gries (2)
Chapter 4

CS 2110 Chapter Notes - Chapter 4: Popping


Department
Computer Science
Course Code
CS 2110
Professor
Gries
Chapter
4

This preview shows half of the first page. to view the full 3 pages of the document.
Section 4 - Collections and Enums
oImportant Classes: Collection<E>, List<E>, Set<E>, Map<K, V>
These implement important interfaces
Iterable<E> (Interface)
Collection<E> (Interface)
List<E> (Interface)
LinkedList<E> (Class)
ArrayList<E> (Class)
Set<E> (Interface)
HashSet<E> (Class)
Map<K, V> (Interface)
Collection<E>
Imagine just a box with a bunch of objects of type E. No order
Has methods
add(E);
contains(Object);
isEmpty();
remove(Object);
size();
List<E>
Implements Collection and inherits methods
Additional methods
get(int);
indexOf(E);
add(int, E);
Has an order, and indexes.
Set<E>
Unordered, but has no duplicates
Has the EXACT same methods as Collection, BUT has a different
specification.
Map<K, V>
This is also an interface, but has TWO generics.
It’s like a dictionary in Python
Methods
put(K, V);
get(Object key);
key is the first argument in put
So this creates a mapping of an obejct from one type to another.
Ex:
put(2017, 3);
get(2017) returns 3
Doesn’t need to be the same types
Ex: put(“twenty-seventeen”, 2017);
get(“twenty-seventeen”) returns 2017
In put, the first object is the key, the second a value.
find more resources at oneclass.com
find more resources at oneclass.com
You're Reading a Preview

Unlock to view full version