| | Types of CollectionSpecialized Collections - Set
A Set is a collection that cannot
contain duplicate elements. It is used to represent sets like the
cards comprising a poker hand, the courses making up a
student's schedule, or the processes running on a machine. (
HashSet, TreeSet) - List
A List is an ordered collection.
Lists can contain duplicate elements. The user of a List generally
has precise control over where in the List each element is
inserted. The user can access elements by their integer index. (ArrayList,
LinkedList, Vector) boolean add(int i, Object o); //Insert o at position i
Object get(int i); //Return the i-th element
Object remove(int i); //Remove the i-th elemet
boolean set(int i, Object o); //Replace the i-th element - Map
A Map is an object that maps keys
to values. Maps cannot contain duplicate keys: Each key can map to
at most one value. If you've used Hashtable(in the API
reference documentation), you're already familiar with the
general flavor of Map. (HashMap,
TreeMap, Hashtable) boolean containsKey(Object key);
boolean containsKey(Object key);
Object get(Object key);
Set keySet();
Object put(Object key, Object value);
Collection values(); - Reference: Annotated
Outline of Collections Framework
|