Current location - Training Enrollment Network - Books and materials - Vacancy reservation in java library
Vacancy reservation in java library
If there were such a way to kill two birds with one stone, ArrayList and LinkedList would have been abandoned long ago.

If your data volume is small, such as less than several hundred thousand, you don't have to consider the performance problem at all, and it makes no difference to use it.

For a particularly large amount of data, we can consider using LinkedList with multiple array lists. When inserting, we only need to insert into a relatively small array list, and most of the time we traverse in a separate array list.

There is also a method called library, that is, when generating ArrayList, some empty spaces are reserved in advance for later insertion, just like the bookshelves in the library are not always full.

If your data is out of order, you can use ArrayList to insert and delete it quickly. First, because there is no order, the insertion can be inserted directly at the end. When deleting, switch between the last thing and the thing to be deleted, and then delete the last thing.