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
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
, restart the program after the problem disappears. But it will come again after a while. Moreover, this problem may be difficult to reproduce in a test environment.
Let's take a quick look at our own code and we know that HashMap is manipulated by multiple threads. The Java documentation says HASHMAP is not thread safe and should be concurrenthashmap.
But here
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
IntroductionHashMap is used frequently in key-value pairs, how does it implement key-value storage?A EntryEntry is an internal interface in the map interface that implements key-value-to-store key. In HashMap, there are entry implementation classes, called entry. The entry class is simple, containing key,value, an externally introduced hash, and a reference to the next entry object, similar to the note node in the linked list of the data structure sec
Let's take a look at this interview question first:
A series of key-value pairs stored in HashMap, where the key is one of our custom types. After placing the HASHMAP, we change the properties of a key on the outside, and then we use the key to remove the element from the HashMap, what will HashMap return?
The
use, can use Concurrenthashmap
Use the Synchronized keyword when you really want to use it
PostScript: In the previous discussion, we saw that if the old elements are copied to the new table in the HashMap, there will be no dead loop, but there will be new problems, the elements are never consistent, because the values on each thread are inconsistent, so be sure to pay attention to thread safety when using the collection type in multi-thread
the use and traversal of HashMap in JavaCategory: Algorithms and data Structures 2011-10-19 10:53 5345 people read reviews (0) favorite reports Hashmapjavastringobjectiteratorlist1: A simple example of using HashMap[Java]View Plaincopy
Package com.pb.collection;
Import Java.util.HashMap;
Import Java.util
The original author dripping: http://www.cnblogs.com/eflylab/archive/2007/01/20/625237.htmlJava provides several ways to hold objects, including the built-in array of languages, and the container Class (container classes) provided in utilities, also known as the Cluster Class (collection classes). The collection is very important in Java, and before the discussion, let's look at some of the classic questions in the interview.1 The difference between C
IncreaseDeleteThe Remove method allows you to delete a specified element.Find*************************************************HashSet can neither use the index of 0 1 2 3 to determine the value of an element, nor use key to determine the value of an element*********************HashSet like this ["AA", "BB"] grow into such a data structure******************HashMap grow into such {a=123, B=hello}Jsonobject very much like {"A": 123, "B": null}
Before Java 8, HashMap and other map-based classes resolved conflicts through chain addresses, using one-way lists to store elements of the same indexed value. In the worst case scenario, this approach lowers the performance of the HashMap get method from O (1) to O (n). To address the problem of hashmap performance du
size represents the number of key-value pairs actually contained in the HashMap.Loadfactor represents a load factor, the larger the value of the Loadfactor, the greater the utilization of the table array, which is equivalent to saving memory space. However, the value of loadfactor increases and the probability of hash collisions increases, which makes the program less efficient. The value of the loadfactor should take into account both memory space and efficiency, with a default value of 0.75.T
prior to Java 8, HashMap and all other hashes table based MAP implementation classes in Ja VA handle collision by chaining , i.e. they uselinked Listto store map entries which ended in the Same bucket due to a collision. If A key end up in same buckets location where an entry are already stored then this entry are just added at the head of the Linked list there. In the worst case this degrades the performa
Problem
Comparison of Java Native
1. TreeMap
2. HashMap
3. ConcurrentSkipListMap
Efficiency of three Map types.
Result
Simulate the insertion and search of massive data within, and test the performance by adding and searching. The results are as follows:
Map type
Insert
Search (within million data records)
10 W
50 W
100 million
150 million
0-1 W
0-25 W
0-50 W
Read the HashMap (1) and javahashmap of Java source code with me.
Recently, I am very busy. I want to learn and discuss some Java source code and its implemented Data Structure with you,
Not a high level of things. If you are interested, take a look.
1. Why Map? Use HashMap as an e
[Previous] Get up and sleep in the morning. Recently, you should pay attention to the same job and rest status. HashMap has a good learning experience. [Definition] Hashmap: A hash, which stores key-value mappings. The null value and the null key are allowed. Java. lang. the Cloneable interface is an empty interface that specifies whether an object can be cloned.
:
System.out.println ("Findingsea". Hashcode ());
System.out.println ("Findingsea". Hashcode ());
System.out.println (New String ("Findingsea"). Hashcode ());
System.out.println (New String ("Findingsea"). Hashcode ());
728795174
728795174
728795174
728795174
You can see that the output of four statements is equal, and it is intuitive to assume that the string type also overloads Hashcode () to return the hash code value based on the contents of the string, so that the same content
1. HashMap Data Structure
In java programming language, the most basic structure is two types, one is array, the other is analog pointer (reference ), all data structures can be constructed using these two basic structures, and HashMap is no exception. HashMap is actually a "linked list hash" data structure, that is, a
/*
The program starts to create a hash ing and then adds the name ing to the balance table. Next, the ing content is displayed by using the set "View" obtained by calling the function entryset. Keywords and values are displayed by calling the getkey () and getvalue () methods defined by map. Entry. Note how deposits are made into evan's account. The put () method automatically replaces the original value associated with the specified keyword with the new value.
*/
Import
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.