Here you can find the source of sortedSet()
public static <T> SortedSet<T> sortedSet()
//package com.java2s; /*/*from www .j a v a 2 s . com*/ Copyright 1996-2010 Ariba, Inc. 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 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. $Id: //ariba/platform/util/core/ariba/util/core/SetUtil.java#16 $ */ import java.util.Comparator; import java.util.SortedSet; import java.util.TreeSet; public class Main { /** Creates an empty SortedSet. <p/> To construct a type-safe <code>Set</code>:<ul> <li><code>Set<X> typesafe = SetUtil.sortedSet()</code> </ul> For a raw <code>Set</code>:<ul> <li><code>Set raw = SetUtil.set()</code> </ul> There will be no compile warnings either way. @return new empty SortedSet @see java.util.SortedSet @aribaapi documented */ public static <T> SortedSet<T> sortedSet() { return new TreeSet<T>(); } /** Creates an empty SortedSet <p/> Given that <code>compX</code> is a <code>Comparator<X></code>, <code>compY</code> is a <code>Comparator<Y></code> (and that <code>Y</code> extends <code>X</code>) and <code>comp</code> is a raw <code>Comparator</code>, the following all compile validly. <ul> <li><code>Set<X> typesafe = SetUtil.sortedSet(compX)</code> <li><code>Set<X> typesafe = SetUtil.<X>sortedSet(compY)</code> <li><code>Set<?> unknown = SetUtil.immutableSet(compX)</code> </ul> The following constructs compile with an unchecked warning:<ul> <li><code>Set<X> typesafe = SetUtil.immutableSet(comp)</code> <li><code>Set raw = SetUtil.immutableSet(compX)</code> </ul> @param comparator the non-null comparator that will be used to sort the <code>Set</code> @return new empty SortedSet @see java.util.SortedSet @aribaapi documented */ public static <T> SortedSet<T> sortedSet(Comparator<? super T> comparator) { return new TreeSet<T>(comparator); } /** Creates a new {@link SortedSet} with the same content as the given <code>SortedSet</code>. <p/> Given that <code>setOfX</code> is a <code>SortedSet<X></code>, <code>setOfY</code> is a <code>SortedSet<Y></code> (and that <code>Y</code> extends <code>X</code>) and <code>raw</code> is a raw <code>SortedSet</code>, the following all compile validly. <ul> <li><code>SortedSet<X> typesafe = SetUtil.sortedSet(setOfX)</code> <li><code>SortedSet<X> typesafe = SetUtil.<X>sortedSet(setOfY)</code> <li><code>SortedSet<?> unknown = SetUtil.sortedSet(setOfX)</code> </ul> The following constructs compile with an unchecked warning:<ul> <li><code>SortedSet<X> typesafe = SetUtil.sortedSet(raw)</code> <li><code>SortedSet raw = SetUtil.sortedSet(setOfX)</code> </ul> @param source the non-null sorted set based on the given SortedSet @return SortedSet containing the elements of the source @see java.util.SortedSet @aribaapi documented */ public static <T> SortedSet<T> sortedSet(SortedSet<? extends T> source) { return new TreeSet<T>(source); } }