Thông tin tài liệu
Map Map // Basic operations // Basic operations V put(K key, V value); V put(K key, V value); V get(Object key); V get(Object key); V remove(Object key); V remove(Object key); boolean containsKey(Object key); boolean containsKey(Object key); boolean containsValue(Object value); boolean containsValue(Object value); int size(); int size(); boolean isEmpty(); boolean isEmpty(); // Bulk operations // Bulk operations void putAll(Map<? extends K, ? extends V> m); void putAll(Map<? extends K, ? extends V> m); void clear(); void clear(); // Collection Views // Collection Views public Set<K> keySet(); public Set<K> keySet(); public Collection<V> values(); public Collection<V> values(); public Set<Map.Entry<K,V>> entrySet(); public Set<Map.Entry<K,V>> entrySet(); // Interface for entrySet elements // Interface for entrySet elements public interface Entry public interface Entry { { K getKey(); K getKey(); V getValue(); V getValue(); V setValue(V value); } V setValue(V value); } Three Map implementations Three Map implementations HashMap HashMap TreeMap TreeMap LinkedHashMap LinkedHashMap Map vs HashTable Map vs HashTable Different types of view. Different types of view. Hashtable does not provide iteration over key- Hashtable does not provide iteration over key- value pairs. value pairs. Map : safely remove entries during iteration Map : safely remove entries during iteration Quizzes Quizzes Generates a frequency table of the words found Generates a frequency table of the words found in its argument list. The frequency table maps in its argument list. The frequency table maps each word to the number of times it occurs in each word to the number of times it occurs in the argument list. the argument list. Comparing two Maps Comparing two Maps Two Map instances are equal if they represent Two Map instances are equal if they represent the same key-value mappings the same key-value mappings Construct a new map from an Construct a new map from an existing Map existing Map Map<K, V> copy = new HashMap<K, V>(m); Map<K, V> copy = new HashMap<K, V>(m); . setValue(V value); } Three Map implementations Three Map implementations HashMap HashMap TreeMap TreeMap LinkedHashMap LinkedHashMap Map vs HashTable Map vs HashTable Different. Construct a new map from an Construct a new map from an existing Map existing Map Map& lt;K, V> copy = new HashMap<K, V>(m); Map& lt;K, V> copy = new HashMap<K, V>(m);. Comparing two Maps Comparing two Maps Two Map instances are equal if they represent Two Map instances are equal if they represent the same key-value mappings the same key-value mappings
Ngày đăng: 16/07/2014, 04:00
Xem thêm: Map.ppt, Map.ppt