Related questions:
You could use a SortedSet e.g. TreeSet with a custom comparator and remove the smallest when the size reachs N.