Java Collections Framework
Java Collections Framework
•Data Structure:
• A specific way of organizing data and operations
to access/use the data
• Structure of the data tied directly to the
implementation
• Which are
abstract data
types?
• Which are
data
structures?
Andrew H. Fagg: CS 2334: Java Collections Framework 5
Collection Interface
What is a collection?
What is a collection?
•“Bag” (or “pile”) of objects
What is a collection?
•“Bag” (or “pile”) of objects (no ordering)
•What is a list?
• Ordered Collection
• Duplicates
•What is a list?
• Ordered Collection
• Duplicates
Approach:
•Create a hash code from the object
• Summarizes the content of the object
• May not be unique
• Eclipse can generate automatically (** demo)
•We’ve seen this method in the Object class
•Use the hash code as an address in a huge
array (called a hash table)
contains(Object o):
•Compute the hash value for the object
•Compute the address in the hash table
•Is anything at that address?
• No: return false
• Yes: is that object equal to o?
contains(Object o):
•Compute the hash value for the object
•Compute the address in the hash table
•Is anything at that address?
• No: return false
• Yes: is that object equal to o?
• Yes: return true
contains(Object o):
•Compute the hash value for the object
•Compute the address in the hash table
•Is anything at that address?
• No: return false
• Yes: is that object equal to o?
• Yes: return true
• No: increment the hash table address