What is the data structure? LinkedList or any other in Java?

I have special data structure requirements that will be used in my Java program. It (Data Structure) should be able to store large amounts of data (not fixed), my main operations are to add at the end, as well as delete / read from the very beginning (LinkedLists look soo so far). But sometimes I also need to be removed from the middle, and this is where LinkedLists are afraid of pain. Can someone suggest me a way around this? Or any optimizations that can make removal less painful with LinkedLists?

Thanks for the help!

+3
source share
5 answers

LinkedHashMap may suit your purpose. You would use an iterator to pull things from the front and find the entry by key when you need to access the middle of the list

+4
source

LinkedListfalls for random access. Deleting without random access search is a constant time and therefore very bad for long lists.

ArrayListusually fast. Insertions and deletions from the middle are faster than you might expect, because block memory moves surprisingly fast. Deleting and pasting next to launch will move all of the following data up or down.

ArrayDequesimilar to ArrayList, only it uses a circular buffer and has a weird interface.

Regular tip: try it.

+3
source

LinkedHashMap - , , . , deque . , , . , "" , , ( ).

: ! , : LinkedMultiSet! LinkedHashMap, . .

0

, . N, , 1/N, . LinkedList ArrayDeque . ( , , , LinkedList , , ArrayDeque , , - , .)

, , , 1/N, LinkedHashSet, -, , , . LinkedList ArrayDeque , , , , .

, , , , " " (.. , ) , , null. ( , , .) , , , , .

0

Source: https://habr.com/ru/post/1734740/


All Articles