I have a report which shows 2-4 million records. I get the records from oracle to java and push it to an excel report. All this is already done!
Now, I also need to add a new tab with top 10 and last 10 records. What would be the best way to do it?
Should i use PriorityQueue implementation in java or use a binary tree to keep a track of top 10 and last 10. I don't need to store the billion records in the data structure. I just need to save 10 at a time. ex:
PriorityQueue<DataObject> queueTop10 = new PriorityQueue<DataObject>(10, topComparator);
PriorityQueue<DataObject> queueLast10 = new PriorityQueue<DataObject>(10, leastComparator);
while (data is coming from database)
{
// push to excel stuff here
queueTop10 .add(dataObject); OR binarytreeTop.insert(dataObject)
queueLast10.add(dataObject); OR binarytreeLeast.insert(dataObject)
}
Please let me know if i can use some other data structure as well.
Thanks