Intricate Java Data Structures

Perhaps the name does not fit, but I could not think of anything else at the moment. My question is what is the difference between LinkedList and ArrayList or HashMap and THashMap .

Does the tree structure already exist for Java (for example: AVL, red-black) or balanced or unbalanced (linked list). If this question is not suitable for SO, please let me know that I will remove it. thank

+3
source share
4 answers

ArrayListand LinkedListare implementations of abstraction List. The first contains list items in the internal array, which is automatically redistributed as necessary to make room for new items. The second design is a doubly linked list of holders, each of which refers to a list item. Although the corresponding operations have identical semantics, they differ significantly in characteristics. For instance:

  • An operation get(int)on ArrayListtakes constant time, but time LinkedListrequires a time proportional to the length of the list.

  • Removing an item using Iterator.remove()takes constant time for LinkedList, but it takes time proportional to the length of the list for ArrayList.

HashMap THashMap Map, -. -, . HashMap , , . THashMap , , , , . , THashMap , HashMap , , /.

. . , .

+3

API docs . .

java.util.TreeMap - .

+2

:

List, , .

ArrayList - , . , . , .

The LinkedList link is implemented as a doubly linked linked list . It does not support random access, but deleting an element when iterating efficiently.

+1
source

As I recall, both (LinkedList and ArrayList) are lists. But they have an internal implementation.

0
source

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


All Articles