【java基础】java集合之HashTable,HashSet,HashMap
2017-12-31 13:56
519 查看
【一】HashSet
(1)HashSet内部维护的是一个HashMap,具体原理见java集合之HashMap
【二】HashTable
(1)HashTable内部维护的是一个Entry的数组。Entry又是一个单项链表的结构。
View Code
(2)
(1)HashSet内部维护的是一个HashMap,具体原理见java集合之HashMap
【二】HashTable
(1)HashTable内部维护的是一个Entry的数组。Entry又是一个单项链表的结构。
private static class Entry<K,V> implements Map.Entry<K,V> { final int hash; final K key; V value; Entry<K,V> next; protected Entry(int hash, K key, V value, Entry<K,V> next) { this.hash = hash; this.key = key; this.value = value; this.next = next; } @SuppressWarnings("unchecked") protected Object clone() { return new Entry<>(hash, key, value, (next==null ? null : (Entry<K,V>) next.clone())); } // Map.Entry Ops public K getKey() { return key; } public V getValue() { return value; } public V setValue(V value) { if (value == null) throw new NullPointerException(); V oldValue = this.value; this.value = value; return oldValue; } public boolean equals(Object o) { if (!(o instanceof Map.Entry)) return false; Map.Entry<?,?> e = (Map.Entry<?,?>)o; return (key==null ? e.getKey()==null : key.equals(e.getKey())) && (value==null ? e.getValue()==null : value.equals(e.getValue())); } public int hashCode() { return hash ^ Objects.hashCode(value); } public String toString() { return key.toString()+"="+value.toString(); } }
View Code
(2)
相关文章推荐
- Java基础面试题(一)集合,hashmap,hashtable,hashset
- java集合HashMap、HashTable、HashSet详解
- JAVA基础--JAVA API集合框架(ArrayList、HashSet、HashMap使用)14
- Java基础知识强化之集合框架笔记66:Map集合面试题之HashMap和Hashtable区别(重要)
- 【Java基础之集合(一)】各种常用集合(Array、ArrayList、HashSet、HashMap、TreeMap等)分析对比
- HashSet HashTable HashMap的区别 及其Java集合介绍
- Java基础知识强化之集合框架笔记78:ConcurrentHashMap之 ConcurrentHashMap、Hashtable、HashMap、TreeMap区别
- 黑马程序员 java 基础 毕向东 面向对象 集合框架 Map HashTable HashMap TreeMap
- HashSet HashTable HashMap的区别 及其Java集合介绍
- java基础_hashmap,hashtable,hashset
- Java基础之集合类如ArrayList、LinkedList、HashMap、HashTable的区别
- Java集合Set、Map、HashSet、HashMap、TreeSet、TreeMap等
- Java 集合系列14之 Map总结(HashMap, Hashtable, TreeMap, WeakHashMap等使用场景)
- 【幻化万千戏红尘】qianfengDay16-java基础学习:HashMap,HashTable,TreeMap
- Java 集合系列之 Map总结(HashMap, Hashtable, TreeMap, WeakHashMap等使用场景)
- Java:集合,Array、Collection(List/Set/Queue)、Map的遍历,比如:ArrayList,LinkedList,HashSet,HashMap
- Java集合之ArrayList,LinkedList,HashMap,HashSet
- JAVA基础学习-集合三-Map、HashMap,TreeMap与常用API
- Java 集合系列14之 Map总结(HashMap, Hashtable, TreeMap, WeakHashMap等使用场景)
- Java集合 -- HashSet 和 HashMap