The difference between java map and list
Map (mapping)
Map is a collection that maps key objects and value objects. Each element of it contains a key object and a value object. Map mainly has the following two implementation classes:
HashMap: HashMap is implemented based on a hash table. The cost of inserting and querying
LinkedHashMap: Similar to HashMap, but when iterating through it, the order in which
TreeMap: TreeMap is implemented based on red-black trees. When viewing
List (list)
The elements of List are stored in a linear manner and can store repeated objects. List mainly has the following two implementation classes:
ArrayList: An array with variable length, which allows random access to elements. Inserting and deleting elements into ArrayList is slow. The implementation of ArrayList expansion in JDK8 is to use the statement newCapacity = oldCapacity (oldCapacity >> 1) (i.e. 1.5 times expansion) in the grow() method to calculate the capacity, and then call the Arrays.copyof() method to copy the original array.
LinkedList: Using linked list data structure, insertion and deletion are fast, but access speed is slow.
Compare | List | Map |
---|---|---|
Inherited interface | Collection | |
Common implementation classes | AbstractList (its common subclasses include ArrayList, LinkedList, and Vector) | HashMap, HashTable |
Common methods | add( ), remove( ), clear( ), get( ), contains( ), size ( ) | put( ), get( ), remove( ), clear( ), containsKey( ), containsValue( ), keySet( ), values( ), size( ) |
Element | Repeatable | Non-repeatable |
Sequence | Ordered | |
Thread safety | Vector thread safety | Hashtable thread safety |
Java introductory tutorials, welcome to learn online!
The above is the detailed content of The difference between java map and list. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)