HashMap is one of the most commonly used tools in the Java development process, and it is often asked during the interview process, which is analyzed by the author's own understanding and numerous information on the web. The author's local JDK version is a 64-bit 1.8.0_171. The following two articles are recommended for reference:
Www.cnblogs.com/little-fly/p/7344285.html
Monkeysayhi.
(Map m): Build an image tree and add all elements in image m(3) TreeMap (Comparator C): Build an image tree and sort the keywords using a specific comparer(4) TreeMap (SortedMap s): Constructs an image tree, adds all the mappings in the image tree S, and sorts with the same comparer as the ordered image s3.HashMap uses Hashcode to quickly find its content, while all elements in the TreeMap are kept in a fixed order,If you need to get an ordered resul
Java HashMap source code parsing 1
HashMap
First, let's look at how the API documentation describes:
Implementation of the Map interface based on the hash table. This implementation provides all optional ing operations and allows the use of null values and null keys. (The HashMap class is roughly the same as tha
Turn from:
http://www.cnblogs.com/fczjuever/archive/2013/04/07/3005997.html 1. Elaborates
In the Java map Traversal way, many articles are recommended to use EntrySet, think it is more efficient than keyset. The reason: The EntrySet method gets all the keys and value sets at a time, and keyset gets only a set of keys, which, for each key, goes to the map to find an extra value, which reduces overall efficiency. So what is the situation?
To understand
The important nature and optimization of HashMap in java, javahashmap
Preface
As HashMap plays an important role in java Development, it is particularly important to summarize some important attributes and optimization points of hashmap, at the same time, it can also improve
same key, and each key can only map one value. The map interface provides three sets of views. The map content can be treated as a set of keys, a set of values, or a set of key-value ing.Hashmap classHashmap is similar to hashtable. The difference is that hashmap is non-synchronous and allows null, that is, null value and null key ., However, when hashmap is treated as a collection (the values () method ca
It seems that there is no source read today, so come and seeJavathe two kinds of hashmap have a different place, before this, first popularize some basic knowledge of HashMap:(1) The element to be put into HashMap is key-value.(2) The bottom is the hash structure that the previous data structure course talked about.(3) To put elements into the
Two ways to HashMap traversal in JavaOriginal address: http://www.javaweb.cc/language/java/032291.shtmlThe first type:Map map = new HashMap ();Iterator iter = Map.entryset (). Iterator ();while (Iter.hasnext ()) {Map.entry Entry = (map.entry) iter.next ();Object key = Entry.getkey ();Object val = Entry.getvalue ();}The efficiency is high, must use this kind of wa
in synchronized block...Synchronized (m) {// Synchronizing on m, not s!Iterator I = s. iterator (); // Must be in synchronized blockWhile (I. hasNext ())Foo (I. next ());}
3. In HashMap, null can be used as a key, and there is only one such key. One or more keys can correspond to null values. When the get () method returns a null value, it can indicate that the key does not exist in HashMap or that the cor
follows:
The relevant code is as follows:
By default, the traversal mode of LINKEDHASHMAP is insert mode, and if you want to explicitly specify a get read mode, set the parameter of//its constructor to true, (false means insert mode) Linkedhashmap Linkedhashmap = new Linkedhashmap ((float) 0.75,true); Linkedhashmap.put ("Name", "Louis"); Linkedhashmap.put ("Age", "the"); Linkedhashmap.put ("Sex", "male"); Linkedhashmap.get ("name");//g
Hashtable extends Dictionary implements Mappublic class HashMap extends Abstractmap implements MapSecondThe methods in Hashtable are synchronous, and the methods in HashMap are not synchronized by default. In the context of multi-threaded concurrency, you can use Hashtable directly, but to use hashmap, you need to increase the synchronization process.ThirdIn Ha
The collection package is the most commonly used package in Java, and it is most commonly used with implementation classes for collection and map two interfaces, where collection is used to hold multiple single objects, and map is used to store key-value pairs in key-value form.
There are two types of interfaces commonly used in collection: List and set, the most obvious difference is that the list supports placing duplicate objects, and set does not
In the Java world, regardless of class or data, the process of its structure is the key to the logic and performance of the entire program. Because I contacted a question about the coexistence of performance and logic, I began to study this problem. Searched the forum of big and Small, also "Java Virtual machine Specification", "apress,.java.collections." (2001),. Bm.ocr.6.0.shareconnector ", and" thinking
, the also look at Concurrenthashmap.In short, unsynchronized to be faster, but in view of Hashtable this concept in the interview than HashMap to come more, so in the face of the test is still used Hashtable bar, in the project development I have always used HashMap.REF:http://blog.csdn.net/steedhorse/article/details/6892569Http://stackoverflow.com/questions/355089/stringbuilder-and-stringbuffer-in-javaHttp://vanillajava.blogspot.de/2013/04/why-synch
Differences between Map and HashMap, Hashtable, and HashSet in Java, hashmaphashsetHashMap and Hashtable both implement the Map interface, both save the K-V pair (key-value Pair); HashSet implements the Set interface, the nature is similar to the Set.
Differences between HashTable and HashMap1. Different Hashtable inherited from the Dictionary class and HashMap
write or write it.What's the difference with Java8 's hashmap?There are hash collisions, such as two hashes that fall on the same index after modulo, or two different keys that have the same hash value.JDK7 's practice is to build a linked list, and then insert the elements on top of each to perform the above judgment.And JDK8 in the chain table length reached 8, and the number of barrels reached 64, built a red black tree, to solve the serious confl
quickly index key?
2. Principle
First, let's look at a simple hashmap implementation in "Thinking in Java":
: Containers/simplehashmap.java//A demonstration hashed Map.
Import java.util.*;
Import net.mindview.util.*; public class Simplehashmap
Simplehashmap constructs a hash table to store the Key,hash function is the modulo operation Math.Abs (Key.hashcode ())% SIZE, uses the link table method
In the Java world, regardless of class or data, the process of its structure is the key to the logic and performance of the entire program. Because I contacted a question about the coexistence of performance and logic, I began to study this problem. Searched the forum of big and Small, also "Java Virtual machine Specification", "apress,.java.collections." (2001),. Bm.ocr.6.0.shareconnector ", and" thinking
In the Java world, regardless of class or data, the process of its structure is the key to the logic and performance of the entire program. Because I contacted a question about the coexistence of performance and logic, I began to study this problem. Searched the forum of big and Small, also "Java Virtual machine Specification", "apress,.java.collections." (2001),. Bm.ocr.6.0.shareconnector ", and" thinking
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.