Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;

import java.util.List;

import com.google.common.collect.Lists;

public class Main {
    /**
     * Sort a collection of objects and then return the a new sorted list so
     * we can keep things functional.  This also works on Collection types that
     * can't easily be sorted (sets, etc).
     *
     */
    public static <T extends Comparable<T>> List<T> sort(Collection<T> input) {
        List<T> result = Lists.newArrayList(input);
        Collections.sort(result);
        return result;
    }

    public static <T> List<T> sort(Collection<T> input, Comparator<T> comparator) {
        List<T> result = Lists.newArrayList(input);
        Collections.sort(result, comparator);
        return result;
    }
}