Java TreeSet treeSet(final Collection collection)

Here you can find the source of treeSet(final Collection collection)

Description

Tree set.

License

Open Source License

Parameter

Parameter Description
T the generic type
collection the collection

Return

the sets the

Declaration

public static <T> Set<T> treeSet(final Collection<T> collection) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *******************************************************************************/

import java.util.Collection;

import java.util.Set;
import java.util.TreeSet;

public class Main {
    /**//www  .  j ava  2s  . co  m
     * Tree set.
     *
     * @param <T> the generic type
     * @param objects the objects
     * @return the sets the
     */
    public static <T> Set<T> treeSet(final T... objects) {
        final Set<T> list = new TreeSet<T>();
        add(list, objects);
        return list;
    }

    /**
     * Tree set.
     *
     * @param <T> the generic type
     * @param collection the collection
     * @return the sets the
     */
    public static <T> Set<T> treeSet(final Collection<T> collection) {
        final Set<T> list = new TreeSet<T>();
        if (collection != null && collection.size() > 0)
            list.addAll(collection);
        return list;
    }

    /**
     * Adds the.
     *
     * @param <T> the generic type
     * @param set the set
     * @param objects the objects
     * @return the sets the
     */
    public static <T> Set<T> add(final Set<T> set, final T... objects) {
        if (objects == null)
            return set;
        for (final T object : objects)
            set.add(object);
        return set;
    }
}

Related

  1. minDiff(TreeSet numbers)
  2. newTreeSet(final Collection c)
  3. toTreeSet(Collection lines)
  4. toTreeSet(Collection collection, Comparator comparator)
  5. treeSet(E... add)
  6. treeSet(final T item)