I have a question.
I was once asked this in the interview —
Suppose you have a queue.A very large queue containing objects. And you cannot fit this queue in the memory. So how do you go about implementing it so that you can add from the end of the queue.And remove from the start of the queue.How is this solution implemented in Java?
Any suggestions..??
There are at least 2 ways, one is to store the data in a flat file and other is to store it in the database.
In case of flat file, you create a file format like:
When you have a :
[current position], and after that increment[current position]with[data x length].In case of database, you create a table like:
When you have a :
More things to note: If you need to remove elements, then it might be better, if you do not remove items as soon as you pop(), but later and many items at a time. You should get more then one element when you read, and not bother flat file / database each time you need an item.