I am calculating a large number of possible resulting combinations of an algortihm. To sort this combinations I rate them with a double value und store them in PriorityQueue
Use SortedSet:
SortedSet items = new TreeSet(new Comparator(...)); ... void addItem(Item newItem) { if (items.size() > 100) { Item lowest = items.first(); if (newItem.greaterThan(lowest)) { items.remove(lowest); } } items.add(newItem); }