JAVA COLLECTIONS SUMMARY

Document Sample
JAVA COLLECTIONS SUMMARY Powered By Docstoc
					                           JAVA COLLECTIONS SUMMARY
                                         CISC 124, fall 2001
                             (all classes & interfaces in java.util)




class ArrayList implements List                   class HashMap implements Map
constructors:                                     constructors:
     ArrayList()                                       public HashMap()
     ArrayList(Collection c)                           public HashMap(Map t)
     ArrayList(int initialCapacity)
                                                  class HashSet implements Set
interface Collection                              constructors:
// Basic Operations                                    HashSet()
boolean add(Object element);                           HashSet(Collection c)
boolean contains(Object element);
boolean isEmpty();                                class LinkedList implements List
Iterator iterator();                              constructors:
boolean remove(Object element);                        LinkedList()
int size();                                       LinkedList(Collection c)
// Bulk Operations
boolean addAll(Collection c);                     interface List extends Collection
void clear();                                     // Positional Access
boolean containsAll(Collection c);                Object get(int index);
boolean removeAll(Collection c);                  Object set(int index, Object element);
boolean retainAll(Collection c);                  void add(int index, Object element);
                                                  Object remove(int index);
class Collections                                 boolean addAll(int index,
static Object max(Collection coll)                               Collection c);
static Object max(Collection coll,                // Search
                  Comparator comp)                int indexOf(Object o);
static Object min(Collection coll)                int lastIndexOf(Object o);
static Object min(Collection coll,
                  Comparator comp)                // Iteration
static void shuffle(List l)                       ListIterator listIterator();
static void sort(List l)                          ListIterator listIterator(int index);
static void sort(List l, Comparator c)            // Range-view
                                                  List subList(int from, int to);
interface Comparable
int compareTo(Object o);

interface Comparator
int compare(Object o1, Object o2)
interface ListIterator extends Iterator   interface SortedSet extends Set
void add(Object o);                       // Range-view
boolean hasNext();                        SortedSet subSet(Object fromElement,
boolean hasPrevious();                    Object toElement);
Object next();                            SortedSet headSet(Object toElement);
int nextIndex();                          SortedSet tailSet(Object fromElement);
Object previous();                        // Endpoints
int previousIndex();                      Object first();
void remove();                            Object last();
void set(Object o);
                                          // Comparator access
interface Map                             Comparator comparator();
// Basic Operations                       class TreeMap implements SortedMap
Object put(Object key, Object value);     constructors:
Object get(Object key);                        TreeMap()
Object remove(Object key);                     TreeMap(Comparator c)
boolean containsKey(Object key);               TreeMap(Map m)
boolean containsValue(Object value);           TreeMap(SortedMap m)
int size();
boolean isEmpty();                        class TreeSet implements SortedSet
// Bulk Operations                        constructors:
void putAll(Map t);                            TreeSet()
void clear();                                  TreeSet(Comparator c)
                                               TreeSet(Collection c)
// Collection Views
public Set keySet();
public Collection values();
public Set entrySet();
// Interface for entrySet elements
public interface Entry {
    Object getKey();
    Object getValue();
    Object setValue(Object value);
}

interface Set extends Collection
     no new methods

interface SortedMap extends Map
Comparator comparator();
SortedMap subMap(Object fromKey,
                 Object toKey);
SortedMap headMap(Object toKey);
SortedMap tailMap(Object fromKey);
Object first();
Object last();