Write code to Add a varargs list of items into a set. - Java java.util

Java examples for java.util:List Operation

Requirements

Write code to Add a varargs list of items into a set.

Demo Code

//package com.java2s;

import java.util.Set;

public class Main {

    public static final <T, U extends T> Set<T> addToSet(Set<T> set,
            U... items) {//from  w  w w . j av a  2s. c  o  m
        if (set != null && items != null) {
            for (int i = 0; i < items.length; i++) {
                set.add(items[i]);
            }
        }

        return set;
    }
}

Related Tutorials