Java Utililty Methods Vector Difference

List of utility methods to do Vector Difference

Description

The list of methods to do Vector Difference are organized into topic(s).

Method

Vectordifference(Vector a, Vector b)
difference
Vector r = new Vector();
for (int i = 0; i < a.size(); i++) {
    boolean inB = false;
    for (int j = 0; j < b.size(); j++) {
        if (a.elementAt(i).equals(b.elementAt(j))) {
            inB = true;
            break;
    if (!inB)
        r.add(a.elementAt(i));
return r;
Vectordifference(Vector vectA, Vector vectB)

This method returns a Vector containing the set of objects contained in vectA that are not contained in vectB.

This method will always return a new, non-null Vector, even if vectA and/or vectB are null.

Vector result = new Vector();
Object item;
if (vectA == null) {
    return result;
if (vectB == null) {
    return (Vector) vectA.clone();
if (vectA.size() + vectB.size() > 10) 
    Hashtable workSetB = new Hashtable();
    Enumeration Enum;
    Enum = vectB.elements();
    while (Enum.hasMoreElements()) {
        item = Enum.nextElement();
        workSetB.put(item, item);
    Enum = vectA.elements();
    while (Enum.hasMoreElements()) {
        item = Enum.nextElement();
        if (!workSetB.containsKey(item)) {
            result.addElement(item);
} else {
    for (int i = 0; i < vectA.size(); i++) {
        item = vectA.elementAt(i);
        if (!vectB.contains(item)) {
            result.addElement(item);
return result;
Vectorminus(Vector vectA, Vector vectB)

This method returns a Vector containing the elements of vectA minus the elements of vectB.

Hashtable workSetB = new Hashtable();
Vector result = new Vector();
Enumeration Enum;
Object item;
if (vectA == null) {
    return result;
result = (Vector) vectA.clone();
...