This issue is not related to collections, not to LinkedList , as shown (which has O(1) adding features).
The likely suspect thus deceives / swaps the memory. Make sure the JVM has enough memory and that the system has more.
Switching from LinkedList to ArrayList (or ArrayDeque ) will support O(1) performance amortization, but may have slightly less overhead. (The overhead, and if such a reduction will even matter, depends on the size of the added objects and the fill factors of the backup storage.)
user166390
source share