Computer Science 136 |
Lecture 6: Vector Operations and Usage
Date: September 21, 2005
public class Vector { // post: constructs a vector with capacity for 10 elements public Vector() // post: adds new element to end of possibly extended vector public void add(Object obj) // post: returns true iff Vector contains the value public boolean contains(Object elem) // pre: 0 <= index && index < size() // post: returns the element stored in location index public Object get(int index) // post: returns index of element equal to object, or -1. // Starts at 0. public int indexOf(Object elem) // pre: 0 <= index <= size() // post: inserts new value in vector with desired index // moving elements from index to size()-1 to right public void add(int index, Object obj) // post: returns true iff no elements in the vector public boolean isEmpty() // post: vector is empty public void clear() // post: remove and return first element of vector equal to parameter // Move later elts back to fill space. public Object remove(Object element) // pre: 0 <= where && where < size() // post: indicated element is removed, size decreases by 1 public Object remove(int where) // pre: 0 <= index && index < size() // post: element value is changed to obj public void set(int index, Object obj) }