Java SortedSet toSortedSet(Comparator comparator, Value... values)

Here you can find the source of toSortedSet(Comparator comparator, Value... values)

Description

Create a set

License

Open Source License

Parameter

Parameter Description
Value the type of values
comparator the comparator
values more of the values

Return

the list

Declaration

@SafeVarargs
public static <Value> SortedSet<Value> toSortedSet(Comparator<Value> comparator, Value... values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Comparator;

import java.util.SortedSet;
import java.util.TreeSet;

public class Main {
    /**//  www  .j  av a2 s.com
     * Create a set
     *
     * @param <Value> the type of values
     * @param comparator the comparator
     * @param values more of the values
     * @return the list
     */
    @SafeVarargs
    public static <Value> SortedSet<Value> toSortedSet(Comparator<Value> comparator, Value... values) {
        SortedSet<Value> set = new TreeSet<>(comparator);

        if (values != null && values.length > 0) {
            for (Value value : values) {
                set.add(value);
            }
        }

        return set;
    }

    /**
     * Create a set
     *
     * @param <Value> the type of values
     * @param values more of the values
     * @return the list
     */
    @SafeVarargs
    public static <Value extends Comparable<Value>> SortedSet<Value> toSortedSet(Value... values) {
        SortedSet<Value> set = new TreeSet<>();

        if (values != null && values.length > 0) {
            for (Value value : values) {
                set.add(value);
            }
        }

        return set;
    }
}

Related

  1. sorted(Iterable input)
  2. sortedByValues(Map map, final boolean asc)
  3. sortedConfigKeys(Iterable> conf)
  4. sortedSet()
  5. splitSorted(String str, String sepStr)
  6. unionSortedSet(Set... sets)
  7. valueSortedMap(Map map, Comparator> comparator)