Here you can find the source of treeSet(final Collection
Parameter | Description |
---|---|
T | the generic type |
collection | the collection |
public static <T> Set<T> treeSet(final Collection<T> collection)
//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; } }