Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Comparator; import java.util.List; public class Main { public static <T extends Comparable<T>> List range(List<? extends T> list, T min, T max) { List<T> result = new ArrayList<T>(); for (T temp : list) { if (temp.compareTo(min) >= 0 && temp.compareTo(max) <= 0) result.add(temp); } return result; } public static <T extends Comparable<? super T>> List range(List<? extends T> list, T min, T max, Comparator<T> comparator) { List<T> result = new ArrayList<T>(); for (T temp : list) { if (comparator.compare(min, temp) >= 0 && comparator.compare(max, temp) <= 0) result.add(temp); } return result; } public static <T> void add(List<? super T> source, T o) { source.add(o); } }