Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;

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

import java.util.List;

public class Main {
    public static <O> List<O> sort(List<O> collection, Comparator<? super O> comparator) {
        return sort(collection, comparator, false);
    }

    public static <O> List<O> sort(List<O> collection, Comparator<? super O> comparator, boolean clone) {
        if (collection == null)
            return collection;

        if (clone) {
            collection = new ArrayList<O>(collection);
        }

        Collections.sort(collection, comparator);
        return collection;
    }

    public static <O> List<O> sort(Collection<O> collection, Comparator<? super O> comparator) {
        if (collection == null)
            return null;

        return sort(new ArrayList<O>(collection), comparator);
    }
}