HashMap
基本方法
-
Returns the number of key-value mappings in this map.
public int size();
-
Returns true if this map contains no key-value mappings.
public boolean isEmpty();
-
Returns a Set view of the keys contained in this map.
public Set<K> keySet();
-
Returns a Collection view of the values contained in this map.
public Collection<V> values();
增
-
Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map.
public void putAll(Map<? extends K, ? extends V> m);
删
-
Removes the mapping for the specified key from this map if present and return the previous value associated with key, or null if there was no mapping for key. (A null return can also indicate that the map previously associated null with key.)
public V remove(Object key);
-
Removes all of the mappings from this map.
public void clear();
改
-
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.
public V put(K key, V value);
查
-
Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
public V get(Object key);
-
Returns true if this map contains a mapping for the specified key.
public boolean containsKey(Object key);
-
Returns true if this map maps one or more keys to the specified value.
public boolean containsValue(Object value);
HashSet
-
Returns the number of elements in this set (its cardinality).
public int size();
-
Returns true if this set contains no elements.
public boolean isEmpty();
-
Returns true if this set contains the specified element.
public boolean contains(Object o);
-
Adds the specified element to this set if it is not already present.
public boolean add(E e);
-
Removes the specified element from this set if it is present.
public boolean remove(Object o);
-
Removes all of the elements from this set.
public void clear();