加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

Java Notes-10

发布时间:2020-12-13 20:08:53 所属栏目:PHP教程 来源:网络整理
导读:Summay: The Map Interface,Collection implementations -Maps storeand retrieve elements with key values e.g: MapString,Date dateMap = new HashMapString,Date();dateMap.put( today,new Date() );Date today = dateMap.get( today ); -Functions: pub

Summay: The Map Interface,Collection implementations

-Maps store and retrieve elements with key values

e.g:

Map<String,Date> dateMap = new HashMap<String,Date>(); dateMap.put( "today",new Date() ); Date today = dateMap.get( "today" );

-Functions:

public V put( K key,V value )//This method adds the specified key/value pair to the map. public V get( K key )//This method retrieves the value corresponding to key from the map. public V remove( K key )//This method removes the value corresponding to key from the map public int size()//Use this method to find the number of key/value pairs in this map public Set keySet()//This method returns a Set that contains all the keys in this map. public Collection values()//Use this method to retrieve all the values in this map

-Map has one child interface, SortedMap . A  SortedMap maintains its key/value pairs sorted
in a particular order according to the key values. 

-All of the methods of the  Collection interface would appear to make sense for  Map,
except for  iterator() . A  Map,again,has two sets of objects: keys and values,and separate
iterators for each. This is why a  Map does not implement  Collection 

-ConcurrentMap, It extends the base  Map interface and adds atomic put,remove,and replace functionality that is
useful for concurrent programming

public V putIfAbsent( K key,V value )//This method associates the value with the key only if the key was not already in use. public boolean remove( Object key,Object value )//This method removes the mapping (key and value) only if the current value asso

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读