|
An Introduction to Collections
in Java |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
java.util.ArrayList Class
void add(int index, Object element)
Object get(int index)
int size()
java.util.ArrayList Class (cont.)
void add(Object element)
void clear()
boolean contains(int index, Object element)
int indexOf(Object element)
java.util.HashMap Class
Object get(Object key)
Object put(Object key, Object element)
int size()
put() Return:
null)
if there was no such value
add() (in ArrayList)
and put() (in HashMap):
Object
ArrayList and a HashMap can only
contain objectsint, double,
etc...
Integer:
Integer(int value)
int intValue()
Double:
Double(double value)
double doubleValue()
HashMap
Object that
uniquely identifies the value Object
Object does not have
an attribute (or attributes) that can be used for
this purpose
HashMap, but you can also use
a HashSet
HashSet
HashMap
We don't know all of the keys unless we keep them in another collection