Adds an object to a Vector if not already contained. - Java java.util

Java examples for java.util:Vector Element

Description

Adds an object to a Vector if not already contained.

Demo Code


//package com.java2s;

import java.util.Vector;

public class Main {
    /** Adds an object to a list if not already contained. */
    public static void tryAdd(Vector vector, Object object) {
        if (object == null) {
            return;
        }//from  ww  w. ja  v  a  2s .co m
        if (!vector.contains(object)) {
            vector.add(object);
        }
    }
}

Related Tutorials