Object Oriented Programming in Java: Advanced Topics Collection Framework
Object Oriented Programming in Java: Advanced Topics Collection Framework
Advanced Topics
Collection Framework
• Trail: Collections
• Lessons:
– Introduction
– Interfaces
– Implementations
– Algorithms
• Interfaces
• Abstract Implementations
• General Purpose Implementations
• Legacy Implementations
• Collection
– A Collection represents a group of objects, known as
its elements
• Behaviors:
– Basic Operations
– Bulk Operations
– Array Operations
// Bulk Operations
boolean addAll(Collection c); // Optional
boolean removeAll(Collection c); // Optional
boolean retainAll(Collection c); // Optional
….
// Array Operations
Object[] toArray();
Object[] toArray(Object a[]);
}
Map
June 1, 2000 Object Oriented Programming in Java (95-707) 16
Java Language Basics
Map Interface Methods
• Basics
– Object put(Object key, Object value);
– Object get(Object key);
– Object remove(Object key)
– int size();
– ...
• Bulk
– void putAll(Map t);
– void clear();
• Collection Views
– public Set keySet();
– public Collection values();
– public Set entrySet();
• Sample code:
static void filter(Collection c) {
for (Iterator i = c.iterator(); i.hasNext(); )
if (!cond(i.next()))
i.remove();
}
• Abstract Implementations
– AbstractCollection
– AbstractSet
– AbstractList
– AbstractMap
}}