I want to save integers in a data structure, but without knowing the number
of integers i might get.
I want the database to be of FIFO kind.
What is best for this purpose?
I want to save integers in a data structure, but without knowing the number
Share
Apart from using a database, if you just have a number of intergers you could write them to a plain file. Plain files retain order, however removing entries can be expensive.
You can write/rewrite 1 million integers in about 0.1 seconds using a plain file.
An efficient collecton for int primitives is TIntArrayList. Its like @JPelletier’s suggestion but wraps a int[]. A million int values should take about 4 MB of memory or disk.
EDIT: This shows that for 1 million numbers ArrayList is a bad choice. Mainly because remove(0) is O(n) rather than O(1)
Prints