# 从10000000个元素里面找出最大的前100个

如题，从最大的10000000个元素里面找出最大的前100个，下面是我的代码实现：

```import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.logging.Logger;

public class FixSizedPriorityQueue<E extends Comparable> {
private final static Logger logger = Logger.getLogger(FixSizedPriorityQueue.class.getName());

private PriorityQueue<E> queue;
private int maxSize; // 堆的最大容量

public FixSizedPriorityQueue(int maxSize) {
if (maxSize <= 0)
throw new IllegalArgumentException();
this.maxSize = maxSize;
this.queue = new PriorityQueue(maxSize, new Comparator<E>() {
@Override
public int compare(E o1, E o2) {
return o1.compareTo(o2);
}
});
}

if (queue.size() < maxSize) {
} else {
E peek = queue.peek();
if (e.compareTo(peek) > 0) {
queue.poll();
}
}
}

public PriorityQueue<E> getQueue(){
return queue;
}

public static void main(String[] args) {
final int length = 10000000;
final int maxSize = 100;

FixSizedPriorityQueue<Integer> fixedQueue = new FixSizedPriorityQueue<Integer>(maxSize);
Random random = new Random();
for(int i =1; i < length; i++){
}

PriorityQueue<Integer> queue = fixedQueue.getQueue();
Object obj = queue.poll();
while(obj != null){
logger.info(obj.toString());
obj = queue.poll();
}
}
}
```

• 0

开心

• 0

板砖

• 0

感动

• 0

有用

• 0

疑问

• 0

难过

• 0

无聊

• 0

震惊