Java集合类常用方法总结 —— Map相关

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();
    
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值