/**
* Returns <tt>true</tt> if this map contains a mapping for the
* specified key.
*
* @param key The key whose presence in this map is to be tested
* @return <tt>true</tt> if this map contains a mapping for the specified
* key.
*/
public boolean containsKey(Object key) {
return getNode(hash(key), key) != null;
}
4.红黑树
/**
* Entry for Tree bins. Extends LinkedMyHashMap.Entry (which in turn
* extends Node) so can be used as extension of either regular or
* linked node.
*/
static final class TreeNode<K,V> extends LinkedHashMap.Entry<K,V> {
TreeNode<K,V> parent; // red-black tree links
TreeNode<K,V> left;
TreeNode<K,V> right;
TreeNode<K,V> prev; // needed to unlink next upon deletion
boolean red;
TreeNode(int hash, K key, V val, Node<K,V> next) {
super(hash, key, val, next);
}
//红黑树暂时还没有仔细研究,红黑树相关的增删改查操作后期再认真分析。
五、总结
仔细分析hashmap源码后,可以掌握很多常用的数据结构的用法。本次笔记只是记录了hashmap几个常用的方法,像红黑树、迭代器等还没有仔细研究,后面有时间会认真分析。