CS61B Guide
  • This site is now deprecated
  • Object Oriented Programming
    • Inheritance
    • Access Control
    • Dynamic Method Selection
    • Java Objects
    • Generic Types
  • Asymptotics
    • Asymptotic Analysis Basics
    • Amortization
    • Asymptotics Practice
  • Abstract Data Types
    • Collections
      • Arrays
      • Linked Lists
      • Sets
      • Stacks and Queues
    • Binary Trees
      • Heaps
      • Balanced BSTs
      • Tries
    • Graphs
    • Hashing and Hash Tables
    • Union Find (Disjoint Sets)
    • Comparables and Comparators
  • Sorting
    • Sorting
  • Algorithms
    • Minimax Algorithm
    • Searching
      • Binary Search
      • Depth First Search (DFS)
      • Breadth First Search (BFS)
    • Shortest Paths
      • Dijkstra's Algorithm
      • A* Search
    • Minimum Spanning Trees
      • Prim's Algorithm
      • Kruskal's Algorithm
  • Misc Topics
    • Modular Arithmetic and Bit Manipulation
    • Exceptions
    • More Resources
Powered by GitBook
On this page
  • Sub-Interfaces
  • Common Functions

Was this helpful?

  1. Abstract Data Types

Collections

PreviousAsymptotics PracticeNextArrays

Last updated 5 years ago

Was this helpful?

Collection is a Java interface for common abstract data types that store multiple items in them.

Sub-Interfaces

    • push(T x): puts x on the top.

    • pop(): Removes the first item. (See the stacks and queues page for more information.)

Common Functions

  • Membership tests contains() and containsAll() that can determine whether or not an element is in the collection.

  • size() to get the number of items in the collection.

  • isEmpty() returns true if there is nothing in the collection.

  • iterator() returns an Iterator object to go through all the values in the collection.

  • toArray() converts the collection to a standard Java array.

  • Optional functions that aren't implemented in the interface: add, addAll, clear, remove, removeAll, retainAll (intersection)

    • Throws UnsupportedOperationException if not implemented.

Lists are indexed sequences with duplication. The two most common types are and .

are non-indexed sequences with no duplication. (That is, every value in a set is unique.)

Maps are key-value pairs. See for a description on one common map implementation, the HashMap. All keys in a map must be unique, but values can be duplicated.

are two ordered collections that have two core behaviors:

Sets
Hashing and Hash Tables
Stacks and Queues
Linked Lists
ArrayLists
An overview of all the Collections in Java.