Search code examples
javaserializable

adding Elements to Serialized ArrayList without loading ArrayList into RAM in JAVA


Is it possible to add Elements into an Array list in java that is already serialized to the disk without reloading it into RAM. I Need this for saving strucutred data from an XML file to load data into a mysql database. The XML File has several GB of Data and the Problem is that i have to store all of the data from the XML file to process the data?


Solution

  • ArrayList, or any other data structure for that matter, is an in-memory data structure. So, whatever you wish to put in this data structure HAS to be loaded into memory(RAM).

    If you're wondering how to load data that is more than the memory size itself, consider loading in batches. e.g. Load the first n entries which fit into the memory constraint and then process them. Once you're done, discard those and load the next batch and so on.