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.Comparator;
import java.util.List;

public class Main {
    public static <T extends Comparable> List range(List<? extends T> list, Object min, Object max) {
        List<T> tList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).compareTo(min) >= 0 && list.get(i).compareTo(max) <= 0) {
                tList.add(list.get(i));
            }
        }
        return tList;
    }

    public static <T> List range(List<? extends T> list, Object min, Object max, Comparator comparator) {
        List<T> tList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (comparator.compare(list.get(i), min) >= 0 && comparator.compare(list.get(i), max) <= 0) {
                tList.add(list.get(i));
            }
        }
        return tList;
    }

    public static <T> void add(List<? super T> source, T o) {
        source.add(o);
    }
}