Code example for Vector

Methods: addElement, contains

0
package bbutils; 
 
import java.util.Vector; 
 
public class Observable { 
 
    private Vector listeners = new Vector();
     
    public void addObserver(Observer observer) {
        if (!listeners.contains(observer)) {
            listeners.addElement(observer);
        } 
    } 
     
    public void removeObserver(Observer observer) {
        if (listeners.contains(observer)) {
            listeners.removeElement(observer);
        }  
    } 
     
    public void notifyObservers() { 
        int size = listeners.size();
        for (int i = 0; i < size; i++) {
            Observer observer = (Observer) listeners.elementAt(i);
            observer.update(this);