Java Utililty Methods TreeSet

List of utility methods to do TreeSet

Description

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

Method

SetgetTreeSet(final Object o, final Class classElement)
Cast an object into a typed TreeSet .
final Set<T> set = new TreeSet<>();
set(set, o, classElement);
return set;
doublegetVariance(TreeSet positions)
get Variance
double average = 0;
int last = 0;
for (Integer position : positions) {
    average += position - last;
    last = position;
average = average / positions.size() - 1;
double var = 0;
...
TreeSetintersection(TreeSet AL1, TreeSet AL2)
intersection
TreeSet<String> returnTreeSet = new TreeSet<String>();
for (String test : AL1) {
    if (!returnTreeSet.contains(test)) {
        if (AL2.contains(test)) {
            returnTreeSet.add(test);
return returnTreeSet;
doubleminDiff(TreeSet numbers)
min Diff
double lowestYet = Double.MAX_VALUE;
double last = -Double.MAX_VALUE;
for (Double d : numbers) {
    double diff = d - last;
    if (diff < lowestYet)
        lowestYet = diff;
    last = d;
return lowestYet;
TreeSetnewTreeSet(final Collection c)
new Tree Set
return new TreeSet<E>(c);
TreeSettoTreeSet(Collection lines)
to Tree Set
TreeSet<String> tree = new TreeSet<String>();
for (String em : lines) {
    tree.add(em);
return tree;
TreeSettoTreeSet(Collection collection, Comparator comparator)
to Tree Set
final TreeSet<T> treeSet = new TreeSet<T>(comparator);
for (T t : collection) {
    treeSet.add(t);
return treeSet;
SettreeSet(E... add)
tree Set
Set<E> result = new TreeSet<>();
if (add != null) {
    result.addAll(Arrays.asList(add));
return result;
SettreeSet(final Collection collection)
Tree set.
final Set<T> list = new TreeSet<T>();
if (collection != null && collection.size() > 0)
    list.addAll(collection);
return list;
TreeSettreeSet(final T item)
tree Set
final TreeSet<T> treeSet = new TreeSet<>();
if (null != item) {
    treeSet.add(item);
return treeSet;