Java Notes-10
来源:互联网 发布:sql登录界面接口源代码 编辑:程序博客网 时间:2024/06/01 08:29
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 mappublic int size()//Use this method to find the number of key/value pairs in this mappublic 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‐ciated with the key equals the supplied valuepublic boolean replace( K key, V existingValue, V newValue)//This method replaces the value associated with the key only if the existing valueequals the existingValue argument.public boolean replace( K key, V value )//This method replaces the value associated with the key only if a mapping alreadyexists for the key
-Arrays are described as consuming constant time for retrieval, but linear time for insertion into or deletion from the body of the array.
-Arrays are useful when you are mostly reading or exclusively appending to the end of the collection.
-Link List holds its elements in a chain of nodes, each referencing the node before and after it (if any).
-Unlike the magic of an array, however, to retrieve an element from a linked list, you must traverse the list from either the head or
tail to reach the correct spot. As you might have guessed, this is a linear-time operation that gets more expensive as the number of elements grows.
-Linked lists are useful when you are doing a lot of insertions or deletions on a collection
-Trees are useful for maintaining and searching large collections of sorted elements.
-A hash map (or hash table, as it is also called) uses a mathematical hash algorithm applied to its key value to distribute its element
-Java Collections implementations
LinkedHashSet
CopyOnWriteArraySet
EnumSet
CopyOnWriteArraySetSortedSet TreeSet
ConcurrentSkipListSetListArrayList
LinkedList
Vector a
Stack
CopyOnWriteArrayListMapHashMap
EnumMap
LinkedHashMap
IdentityHashMap
Hashtable aConcurrentMapConcurrentHashMap
ConcurrentSkipListMapSortedMapTreeMapQueue / DequeueLinkedList
ArrayDeque
PriorityQueue
DelayQueue
SynchronousQueue
ConcurrentLinkedQueue
ConcurrentLinkedDequeueBlockingQueueArrayBlockingQueue
LinkedBlockingQueue
PriorityBlockingQueue
Next Synchronized and Unsynchronized Collections...
- Java Notes-10
- Java Notes-10
- Java - Notes
- notes[java]
- java notes
- java notes
- Java Notes
- Java Notes
- Java 游戏开发Notes
- Java Thread - Notes
- Java 游戏开发Notes
- Java-Notes Documents
- java 访问notes domino
- java 读取notes数据库
- Java Container Learning notes
- Java 游戏开发Notes
- Java Notes: ArrayList
- Notes:java comile flag
- 数据结构 - 图的遍历
- 《C语言及程序设计》实践参考——查成绩
- Android视频播放项目总结之 适配器绑定视频信息列表显示到界面(适配器简单优化)
- Boost线程库学习笔记
- 使用UltraISO制作U盘启动盘的方法(图文教程)
- Java Notes-10
- 《C语言及程序设计》程序阅读——字符数组与字符串处理
- 《C语言及程序设计》程序填空——字符数组与字符串处理
- 《C语言及程序设计》实践项目——字符数组与字符串处理
- lightOJ 1245 Harmonic Number (II) 利用图形求整数点
- DW
- java基础入门-动态绑定-调用方法的过程
- 原-补-反-移
- linux 下安装python+django+mysql配置环境