The difference between HashMap and LinkedHashMap in java
Nov 18, 2019 pm 02:19 PMHashMap
HashMap is the most commonly used Map. It stores data according to the HashCode value of the key. Its value can be obtained directly according to the key. It has The access speed is very fast, and the order during traversal is completely random. HashMap only allows one key to be Null and allows multiple values ??to be Null.
Features: Completely random
Advantages: Random access, fast value acquisition
Disadvantages: Multiple threads writing HashMap at the same time may cause data inconsistency. If synchronization is required, use Collection's synchronizedMap
method or use ConcurrentHashMap
LinkedHashMap
LinkedHashMap is a subclass of HashMap that saves the insertion of records The order is different from the random traversal of HashMap. When traversing with Iterator, the record obtained first must be inserted first, similar to OrderedDict in python.
The traversal speed will be slower than HashMap, but there is an exception: when the capacity of HashMap is large and the actual data is very small, because the traversal speed of HashMap is related to its capacity, while LinkedHashMap is only related to the actual amount of data. related.
TreeMap
TreeMap implements the SortMap interface and can sort the records it saves by key. The default is ascending order by key. You can also specify a sorting comparator to traverse the TreeMap When , the records obtained are sorted by key.
Select Map based on data
Generally, what we use most is HashMap. To insert, delete and locate elements in Map, HashMap is the best choice. . But if you want to iterate over keys in natural order or custom order, then TreeMap will be better. If you need the output order to be the same as the input, you can use LinkedHashMap, which can also be arranged in reading order.
Recommended tutorial: Java tutorial
The above is the detailed content of The difference between HashMap and LinkedHashMap in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics











Go language can be used for scientific calculations and numerical analysis, but it needs to be understood. The advantage lies in concurrency support and performance, which is suitable for parallel algorithms such as distributed solution, Monte Carlo simulation, etc.; community libraries such as gonum and mat64 provide basic numerical calculation functions; hybrid programming can be used to call C/C and Python through Cgo or interface to improve practicality. The limitation is that the ecosystem is not as mature as Python, the visualization and advanced tools are weaker, and some library documents are incomplete. It is recommended to select appropriate scenarios based on Go features and refer to source code examples to use them in depth.

USDC is safer than USDT. 1. In terms of reserve assets and transparency, USDC is composed of cash and US Treasury bonds, and is audited and reported publicly every month by Deloitte, with high transparency; while USDT reserves are complex, audit institutions are not top-level, and have low transparency. 2. In terms of regulation and compliance, USDC is issued by the US company Circle, which holds multiple payment licenses and is actively compliant; USDT is under tension due to historical issues and regulatory relations. 3. In terms of issuance entities, USDC was jointly launched by Circle and Coinbase, with a strong background and a clear compliance image; USDT is closely related to Bitfinex, and its independence is questioned. Therefore, users with high security requirements recommend choosing USDC, and those with high liquidity are required

High-frequency trading is one of the most technologically-rich and capital-intensive areas in the virtual currency market. It is a competition about speed, algorithms and cutting-edge technology that ordinary market participants are hard to get involved. Understanding how it works will help us to have a deeper understanding of the complexity and specialization of the current digital asset market. For most people, it is more important to recognize and understand this phenomenon than to try it yourself.

How to get started with AngularMaterial? First run ngadd@angular/material to install and configure, secondly, introduce components such as MatButtonModule as needed, then import and use components in the module, and finally add global styles and fonts; the advantages of AngularMaterial include a unified design language, rich components, good documentation and community support, and strong customization; other alternatives include NG-ZORRO, PrimeNG, ClarityDesign and IonicforAngular, and when choosing, you should consider comprehensively based on project needs and team familiarity.

Understand core components: Producers publish events to Topics, Consumers subscribe and process events, KafkaBroker manages message storage and delivery; 2. Locally build Kafka: Use Docker to quickly start ZooKeeper and Kafka services, expose port 9092; 3. Java integration Kafka: introduce kafka-clients dependencies, or use SpringKafka to improve development efficiency; 4. Write Producer: configure KafkaProducer to send JSON format order events to orders topic; 5. Write Consumer: Subscribe to o through KafkaConsumer

The main difference between Bitcoin and altcoins is: 1. Bitcoin is the first cryptocurrency, positioned as "digital gold" and focuses on value storage, while altcoins generally refer to other crypto assets with diverse application directions; 2. The value of Bitcoin comes from scarcity, global consensus and decentralized security network, and the value of altcoins depends on project team, technical architecture and practical applications; 3. Bitcoin has the largest market value, strong liquidity, and high institutional recognition. Only the leading currency in the altcoins is relatively stable, and most of them have poor liquidity and risk of being manipulated; 4. Bitcoin has relatively low volatility, strong resistance to decline and manipulation, the price of altcoins fluctuates violently, rise and fall rapidly, and faces higher risks such as technical loopholes and project runaway; 5. Bitcoin has long-term value storage potential and has gradually become an institutional configuration

The core difference between ETH and ETC comes from the hard fork after the DAO incident in 2016. 1. ETH chose to recover losses through hard forks, adhere to the concept of pragmatism, and support blockchain variability to cope with crises; 2. ETC adheres to "code is law" and maintains the immutability of the original chain; 3. ETH has a huge and active developer ecosystem and PoS consensus, with high security and wide application; 4. ETC follows the PoW mechanism, has slow development, a small ecosystem, has encountered 51% attacks, and has weak market influence; 5. Both can be traded on mainstream exchanges such as Binance, Ouyi, Huobi, and Gate.io, among which ETH is the second largest crypto asset in the world, with liquidity and recognition far exceeding ETC.

The core methods to prevent SQL injection include: 1. Use PreparedStatement precompiled statements to ensure that the input is processed as data; 2. Whitelist verification, length limit and special character escape of the input; 3. Correctly use ORM frameworks such as Hibernate and MyBatis to avoid splicing SQL; 4. Do not expose error information, scan for vulnerabilities regularly, and restrict database permissions. These measures jointly ensure the SQL security of Java applications.
