My Java application has to work with very large ArrayLists full of integer values. Manipulating these ArrayLists is not a problem, but these ArrayLists also need to be transmitted and stored, which I haven't found an efficient way to do yet.
The list consists largely of consecutive integer values, for example:
1 -> 5000
2 -> 5001
3 -> 5002
4 -> 5003
5 -> 5005
6 -> 5006
7 -> 5007
So I would have imagined that the list could e.g. be transferred as follows: "5000-5003; 5005-5007". Then I could put them back together into a list at the other end. Unfortunately, the list is not sorted.
How can one efficiently compress the list to save it in a database or in text form and transfer it to another device?
start + number of elements. That means5000-5003could be expressed as5000,4and5005-5007would become5005,3. If the average number of elements could be very low using an int,byte pair would even be more efficient - larger sequences could still be represented as smaller chunks (e.g.0-300could become0,255,255,46). Of course this only works if there are sequences and the list is sorted to some extent, otherwise you could as well send individual ints.