Map不同实现对null值的限制不同

星期五, 2020-10-23 | Author: Lee | JAVA-and-J2EE | 1,994 views

Map不同实现对null值的限制不同,罗列如下:

key value 线程安全
HashTable 不可为null 不可为null 线程安全
ConcurrentHashMap 不可为null 不可为null 线程安全
TreeMap 不可为null 可为null 线程不安全
HashMap 可为null 可为null 线程不安全

HashTable由于实现上使用key的hashcode()方法,所以key不能为null。ConcurrentHashMap需要使用key的hashcode(),TreeMap使用key的compare()方法排序,所以key不能为null。

Tags:

文章作者: Lee

本文地址: https://www.pomelolee.com/2117.html

除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址

No comments yet.

Leave a comment

Search

文章分类

Links

Meta