Container -- TreeMap, treemap
I. Overview
In the implementation of Map, in addition to our most common HashMap with unordered KEY values, there are also KEY ordered maps, which are commonly used in two categories, one class is a Map of the size ordered by the KEY value, which represents TreeMap, And the other class maintains the insert order of Map, which represe
If you want to get the member attribute of an object, the member type is package-level private internal class, and the member is private, how can you get this member?
Ideas:
Suppose we want to study treemap, and we want to get the root of the treemap object.
First, treemap. Class.Getdeclaredclasses () to get all internal classesFor example, if root is an in
1. Overview of the TreeMap class:The key is a red-black tree structure that guarantees the ordering and uniqueness of the keys .2. TreeMap Case:Treemapcode example:1 Packagecn.itcast_04;2 3 ImportJava.util.Set;4 ImportJava.util.TreeMap;5 6 /*7 * TreeMap: is based on the red-black tree map interface implementation. 8 * 9 * hashmapTen * Key: String One * Value: S
[Java learning notes] The Map interface sub-interface --- TreeMap, learning notes --- treemap
Similar to TreeSet, TreeMap can sort elements in a set and maintain the uniqueness of elements.
It should be noted that Comparable (The implementation interface should overwrite the comparaTo method) is used by Comparator.
1 import java. util. iterator; 2 import java. u
Summary
In this chapter, we learn about TreeMap.We first have a general understanding of TreeMap, and then learn its source, and finally through the example to learn to use TreeMap. The content includes:The 1th part TreeMap IntroductionPart 2nd TREEMAP Data structure3rd Part TREEM
[Java Collection source code analysis] TreeMap source code analysis
Reprinted please indicate the source: http://blog.csdn.net/ns_code/article/details/36421085
Preface
This article does not intend to extend the style of the previous articles (add comments to all source code), because we need to understand all the source code of TreeMap. For bloggers, it really takes a lot of time and experience. At present,
Reprint Please specify the Source: http://blog.csdn.net/ns_code/article/details/36421085PrefaceThis article does not intend to perpetuate the previous few styles (add gaze to all the source code), because to understand the full source of TreeMap. For bloggers. It really takes a lot of time and experience. It seems unlikely that there will be so much time to spend at the moment. Therefore, it is intended to read the source code on the
http://cmsblogs.com/?p=1013 original source.TreeMap implementation is the implementation of red-black tree algorithm, so to understand the treemap must have a certain understanding of red and black trees, in fact, the name of this blog is called: According to the red-black tree algorithm to analyze the implementation of TREEMAP, But it's better to be consistent with the Java Improvement blog or to be called
Introduction: TreeMap and TreeSet are two important members of the Java Collection Framework, where TreeMap is a common implementation class for the Map interface, and TreeSet is a common implementation class for Set interfaces. Although the interface specification implemented by HASHMAP and HashSet is different, the TreeSet is implemented through TREEMAP, so the
Let's start by describing what a map is. In the array we index the content by the array subscript, and in the map we index the object by object, the object to index is called key, and its corresponding object is called value. This is what we call a key-value pair.HashMap quickly find its content through hashcode, and all elements in TreeMap remain in a fixed order, and if you need to get an ordered result you should use
HashMap quickly find its content through hashcode, and all elements in TreeMap remain in a fixed order, and if you need to get an ordered result you should use TREEMAP (the order of the elements in HashMap is not fixed).HashMap non-thread-safe TreeMap non-thread safeThread SafetyIn Java, thread safety generally manifests itself in two ways:1, multiple thread acce
First, we will introduce what Map is. In the array, We index its content through the array subscript, while in the Map, we index the object through the object. The object to be indexed is called the key, the corresponding object is value. This is what we usually call a key-value pair.
HashMap uses hashcode to quickly search its content, while all elements in TreeMap maintain a fixed order, if you need to get an ordered result, you should use
Let's start by describing what a map is. In the array we index the content by the array subscript, and in the map we index the object by object, the object to index is called key, and its corresponding object is called value. This is what we call a key-value pair.HashMap quickly find its content through hashcode, and all elements in TreeMap remain in a fixed order, and if you need to get an ordered result you should use
and value are String,key values of 1, 2, 3 ... 1000000:
mapString key, value;for (i = 1; I key = "" + I;value = "value";Map.put (key, value);}
HashMap-2, size 1 million, key and value are string,key values of 50, 100, 150, 、......、 50000000:
mapString key, value;for (i = 1; I key = "" + (I *);value = "value";Map.put (key, value);}
2.1.2 TreeMap test Data TreeMap-1,
Similarities and differences of TreeMap and TreeSet:Same point:
Both TreeMap and TreeSet are ordered collections, meaning that the values they store are well-sequenced.
TreeMap and TreeSet are non-synchronous collections, so they cannot be shared across multiple threads, but can be synchronized using method Collections.synchroinzedmap ()
Objective
This article does not intend to extend the previous several styles (add the annotation to all source code), because to understand all the source code of TreeMap, for bloggers, it does take a lot of time and experience, it seems unlikely to have so much time to invest, Therefore, this is intended to be through the reading source to the TreeMap has a macro grasp, and some of the implementation of s
I. OverviewTreeMap is based on red and black trees. Because TreeMap implements the Java.util.sortMap interface, the mappings in the collection are in a certain order, depending on the natural order of their keys or sorted according to the comparator provided when the mapping is created, based on the construction method used. In addition, the key object in the TreeMap is not allowed to be null.1. What is a r
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.