/*
-
HashMap -->线程不安全
-
底层是由哈希表实现的
-
hashmap去重–>根据key去重,自定义引用数据类型数据:hashCode()和equals()
-
Hashtable 和HashMap类似 -->线程安全的
-
TreeMap
-
底层是由红黑树实现的
-
TreeMap去重–>根据key去重,自定义引用数据类型数据:内部|外部比较器
-
选择:如果想要根据key做某种规则的排序选择TreeMap,否则选择HashMap
*/
public class HashMapDemo {
public static void main(String[] args) {
// HashMap<Person, Boolean> map=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);
}
}