If you implement your own list, and you decide to use the storage mechanism of the basic primitives. Thus, using an array (rather than an arraylist) may be where you start.
For easy implementation, your strategy should consider the following.
Decide how to expand your list. You can create copies of data blocks of 200 cells at a time. You would use only 199 because you could use the last cell to store the next block of allocation.
Such a linked list is terrible, so you can use a master block to store all instances of blocks. You create a master block of size 100. You start with one data block 200 and store its ref in master [0]. As the size of the list grows, you gradually save the ref of each new data block to master [1] .... master [99], and then you may have to recreate the main list to store 200 links.
For efficiency reasons, when you delete a cell, you should not actually destroy it immediately. You let it hang until enough deletion occurs so you can recreate the block.
You need to note somehow that the cell has been deleted. So the answer is obvious, of course, you can set it to zero, because you are the king, emperor, dictator who decides how the cell is marked as deleted. Using null is a great and common way. If you use null, you need to prevent null values ββfrom being entered as data in your list class. You would have to make an exception if such an attempt is made.
You need to develop and write a garbage collection procedure and strategy to combine the list, recreating blocks to remove invalid cells in the mass. The JVM does not know that this is "deleted" data.
You need a register to count the number of deletions, and if this threshold is crossed, garbage collection will be collected. Or you ask the programmer to call the compact () method. Because if deletions are sparse and distributed between different data blocks, it is also possible to delete null / deleted cells. You can only combine adjacent blocks and only if the sum of the holes in both blocks is up to 200. Obviously,
Perhaps when data is added to the list, you intentionally leave zero spaces between the data. Itβs like driving along the street, and you see that the addresses of the houses increase by ten, because the city decided that if people want to build new houses between existing houses. This way you do not need to recreate and break the block every time an insert occurs.
Therefore, the answer is obvious to you, of course, you can write null to indicate that the cell has been deleted, because this is your list class management strategy.