Java Utililty Methods SortedSet

List of utility methods to do SortedSet

Description

The list of methods to do SortedSet are organized into topic(s).

Method

Iterablesorted(Iterable input)
sorted
TreeSet<T> ret = new TreeSet<T>();
for (T t : input) {
    ret.add(t);
return ret;
SortedSet>sortedByValues(Map map, final boolean asc)
sort a map by value
SortedSet<Map.Entry<K, V>> sortedEntries = new TreeSet<Map.Entry<K, V>>(new Comparator<Map.Entry<K, V>>() {
    public int compare(Map.Entry<K, V> e1, Map.Entry<K, V> e2) {
        int compareTo = e1.getValue().compareTo(e2.getValue());
        int direct = 1;
        if (!asc) {
            direct = -1;
        return compareTo * direct;
...
TreeSetsortedConfigKeys(Iterable> conf)
Take a configuration and return a sorted set
TreeSet<String> sorted = new TreeSet<String>();
for (Map.Entry<String, String> entry : conf) {
    sorted.add(entry.getKey());
return sorted;
SortedSetsortedSet()
Creates an empty SortedSet.
return new TreeSet<T>();
SortedSetsplitSorted(String str, String sepStr)
Split the given string using the given separate, returning the components as a SortedSet.
SortedSet<String> result = new TreeSet<String>();
if (str != null) {
    for (String value : str.split(sepStr)) {
        if (value.length() > 0) {
            result.add(value);
return result;
SortedSettoSortedSet(Comparator comparator, Value... values)
Create a set
SortedSet<Value> set = new TreeSet<>(comparator);
if (values != null && values.length > 0) {
    for (Value value : values) {
        set.add(value);
return set;
SortedSetunionSortedSet(Set... sets)
union Sorted Set
SortedSet<T> unionSet = new TreeSet<T>();
for (Set<T> set : sets) {
    unionSet.addAll(set);
return unionSet;
MapvalueSortedMap(Map map, Comparator> comparator)
value Sorted Map
Set<Entry<K, V>> valueSortedEntries = new TreeSet<Entry<K, V>>(comparator);
for (Entry<K, V> entry : map.entrySet()) {
    valueSortedEntries.add(entry);
Map<K, V> sortedMap = new LinkedHashMap<K, V>(map.size());
for (Entry<K, V> entry : valueSortedEntries) {
    sortedMap.put(entry.getKey(), entry.getValue());
return sortedMap;