Java Learning Note-HashMap

1.What is map

As the difine of map in Collins:"Map is a drawing of a particular area,showing its main features as they would appear if you looked at them from above".In programming language,the mean of map is similar with the defination in the dictionary,that is a value can be find from a map(Key).Return the the strict defination of map in Computer Science,map is a type of associative container,which supports high efficience look up,and the elements in a map are key-value pairs:The key serves as an index into the map,and the value represents the data associated with that index.In python,there also is a datastructure similar with "map",however,it's called dictionary,and both Java and C++ this datastructur is called map.The key points of map is as follows:

point 1:The elements in map is key-value pair,key is the index of each element in the map,and value is the contains of this element.

point 2:The key-value pair has a one-to-one relationship,one key corresponds to identify value,there is on other situations.in another words,one key can not correspond to multi values,on the contrary,several different values can not correspond to one key.

point 3:Map is one of the collections member,it has a high searching effience,because,once you make sure the key or the value of an element in the map,you can easily find a correspond value or key.And the practice implements of map would be introduced in the later part of this blog.

2.HashMap

Before I talk about Hashmap's internal implements,I suppose to show the inheritance structure of this  Container.

Map-->AbstractMap-->HashMap

As you can see from the inheritance relationship of HashMap,It extends from AbstractMap,which implements the base interface of Map.Now,I suppose to learn more about this Container from the source code of hashmap,and figure out the implement method of this container.

//Interface Map 
public interface Map<K,V>{
    
    //Returns the number of key-value pair in Map.
    int size();

    //Returns true if the map is empty,otherwise return false.
    boolean isEmpty();

    //Finds out whether the map contains a specifid key or not.The reason that the                                     

    //arguments arguments is a Object class is that Object is the base class of all              

    //class in java.     
    boolean containKey(Object key);

    //Finds out whether this map contains a specified value or not,return a boolean
    boolean containValue(Object value);

    //Gets the key corresponding value and return it,it's type is the template V.
    V get(Object key);

    //Deletes the key corresponding value and return it,it's type is the template V. 
    V remove(Object key);

    //copies all of the elements in the specified map to this map.and the input args 
    //is a Map<? extends K,? extends V>,"?" is extends from K and V,so any subclass of
    //K,V are legal.
    void putAll(Map<? extends K,? extend V> m)
    

    //Deletes all elements in this map and returns anything.
    void clear();

    //Returns a key set of this map.
    Set<K> keySet();

    //Returns a values collection of this map.
    Collection<V> values();
    
}


 

 

3.The Difference Between HashMap and HashTable

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值