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

Java examples for java.util:Vector Element

Description

Adds an object to the start of a Vector if not already contained.

Demo Code


//package com.java2s;

import java.util.Vector;

public class Main {
    /** Adds an object to the start of a list if not already contained. */
    public static void tryInsert(Vector vector, Object object) {
        if (object == null) {
            return;
        }/*from   w  ww .  j a va 2  s  . c  om*/
        if (!vector.contains(object)) {
            vector.insertElementAt(object, 0);
        }
    }
}

Related Tutorials