search
HomeJavaJavaBaseThe difference between java map and list

The difference between java map and list

Nov 18, 2019 am 11:24 AM
javalistmap

The difference between java map and list

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 is fixed and can be adjusted by setting the capacity and load factor through the constructor. Container performance.

LinkedHashMap: Similar to HashMap, but when iterating through it, the order in which is obtained is its insertion order, or the least recently used (LRU) order.

TreeMap: TreeMap is implemented based on red-black trees. When viewing , they will be sorted. TreeMap is the only Map with a subMap() method, which can return a subtree.

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
##php Chinese website, a large number of free

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

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

SublimeText3 Mac version

God-level code editing software (SublimeText3)