Java tutorial
//package com.java2s; import java.util.SortedSet; public class Main { public static <T> SortedSet<T> updateMovieListIfNeeded(SortedSet<T> queryResult, SortedSet<T> orderedMovies, int nbResultsMax) { // add incoming to existing list - order ensure by TreeSet queryResult.addAll(orderedMovies); // keep only the "top of list", cap by the query spec return queryResult; } }