Created
May 24, 2018 13:12
-
-
Save wmydz1/332f9b26b6c4bf8f12a7fadfa5de5232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HashMap和HashTable的区别 | |
1,HashMap线程不安全,HashTable是线程安全的。 | |
2,HashMap的key和value都可以为null,但是HashTablekey和value都不能为null。 | |
3,对于HashMap如果get返回null,并不能表明HashMap不存在这个key, | |
4,如果需要判断HashMap中是否包含某个key,就需要使用containsKey这个方法来判断。 | |
5,如果是多线程环境也不建议使用HashTable,而是使用ConcurrentHashMap,ConcurrentHashMap也是线程安全的, | |
并且比HashTable性能好。 | |
6,HashMap在确定数据大小的情况想,建议初始化一个合适的容量,否则可能会面resieze,resize操作是一个非常耗时的过程。 | |
如果把自定以的类作为HashMap或者HashTable的key,就需要重写hashCode和equals方法。 | |
通俗点讲,==是看看左右是不是一个东西。equals是看看左右是不是长得一样。 | |
如何记住嘛。如果单纯是想记住, | |
==:等于。 | |
equals:相同。 | |
两个长得一样的人,只能说长的相同(equals),但是不等于他们俩是一个人 | |
==是引用一致判断,equals是内容一致判断 | |
ArrayList更适合读取数据,linkedList更多的时候添加或删除数据。 | |
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构。 | |
2.对于随机访问get和set,ArrayList觉得优于LinkedList,因为LinkedList要移动指针。 | |
3.对于新增和删除操作add和remove,LinedList比较占优势,因为ArrayList要移动数据。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment