Data structures for hashMap, list and set

Can anyone advise me to go deeper into the Data Structures used and how it is implemented in the Util List, Set and Maps page.

In the interview, most of the questions will be about Algorithms, but I have never seen the implementation details, can anyone post this information.

+2


a source to share


4 answers


To see how Java implements collections, the final place to go is the source code, freely available. Typically, lists are implemented as arrays (ArrayList) or linked lists (LinkedList); sets - either hashtables (HashSet) or trees (TreeSet); and maps are hashtables (HashMap).



The algorithms for manipulating arrays, linked lists, hash tables, and binary or n-ary trees (add, delete, search, sort) are complex enough on their own to make the entire course necessary to cover them. Anyone who makes their own program design usually needs to understand these algorithms and their compromise execution by heart. There is no substitute for textbook study and / or practice.

+3


a source


The API source is available, get the JDK and open the src.zip file from the installation folder.



+3


a source


You can always open the source files, everything is there, however I would not recommend it as they are usually quite difficult to understand. Instead, I would try to find the underlying data structure and look at it. Wikipedia contains most of the information you want to know on these topics, and google contains absolute rest.
A list is just a dynamic array ,
Set is a ... set ,
AND maps are usually hash tables , driven by the hash of the key, and stored as a key-value pair.
If you are going to dive into the source code, I recommend reading "how this is possible" because otherwise it will be difficult to understand, especially the hash table.

+1


a source


ArrayList : array

LinkedList : double linked list (input objects)

HashMap : an array of Entry objects each element pointing to a single list

HashSet : internally uses HashMap, stores data as Key and dummy object (class object) as value in map.

TreeMap . Implementation of Entry objects in Red-Black.

TreeSet : Internally uses TreeMap. Enter as data object and dummy object as value.

* Entry : is an inner class in these collections and usually has a key, value, references to other Entry objects, etc.

0


a source







All Articles