/*
-
HashMap -> thread safe
-
The bottom layer is achieved by the hash table
-
hashmap deduplication -> The key to the weight data from the reference data types defined: hashCode () and equals ()
-
Hashtable and HashMap similar -> thread-safe
-
TreeMap
-
The bottom layer is implemented by a red-black tree
-
TreeMap deduplication -> The key to the weight, the custom data reference data types: internal | external comparator
-
Select: If you want to do some sort of rule based on key selection TreeMap, or select HashMap
* /
public class HashMapDemo {
public static void main (String [] args) {
// HashMap <the Person, Boolean> = the Map new new HashMap () ;TreeMap<Person, Boolean> map=new TreeMap((o1,o2)->((Person)o2).getAge()-((Person)o1).getAge()); map.put(new Person("饶瑞",22),true); map.put(new Person("林源",24),false); map.put(new Person("韩龙",23),true); map.put(new Person("徐敏生",20),false); map.put(new Person("林源2",24),true); System.out.println(map);
}
}