Java How to Program学习笔记_第十六章_Java集合(Generic Collections)——章节小结(Summary)

自己选择的路,含着泪也要走完,继续学习Java!

Summary 

Section 16.1 Introduction

 • The Java collections framework provides prebuilt data structures and methods to manipulate  them. 

Section 16.2 Collections Overview 

• A collection is an object that can hold references to other objects. 

• The classes and interfaces of the collections framework are in package java.util

Section 16.3 Type-Wrapper Classes

 • Type-wrapper classes (e.g., Integer, Double, Boolean) enable programmers to manipulate primitive type values as objects. Objects of these classes can be used in collections. 

Section 16.4 Autoboxing and Auto-Unboxing 

• Boxing converts a primitive value to an object of the corresponding type-wrapper class.  Unboxing (p. 687) converts a type-wrapper object to the corresponding primitive value. 

• Java performs boxing conversions and unboxing conversions automatically. 

Section 16.5 Interface Collection and Class Collections

 • Interfaces Set and List extend Collection, which contains operations for adding, clearing,  comparing and retaining objects in a collection, and method iterator to obtain a  collections Iterator

• Class Collections provides static methods for manipulating collections. 

Section 16.6 Lists

• A List is an ordered Collection that can contain duplicate elements. 

• Interface List is implemented by classes ArrayList, LinkedList and Vector. ArrayList is a resizable-array implementation.

LinkedList is a linked list implementation of a List

• Java SE 7 supports type inferencing with the <> notation in statements that declare and create  generic type variables and objects. 

Iterator method hasNext determines whether a Collection contains another element.  Method next returns a reference to the next object in the Collection and advances the Iterator

• Method subList returns a view into a List. Changes made to this view are also made to the List

• Method clear removes elements from a List

• Method toArray returns the contents of a collection as an array. 

Section 16.7 Collections Methods

 • Algorithms sort, binarySearch, reverse, shuffle, fillcopy, addAll, frequency and disjoint operate on Lists. Algorithms min and max  operate on Collections

• Algorithm addAll appends all the elements in an array to a collection, frequency  calculates how many elements in the collection are equal to the specified element, and  disjoint determines whether two collections have elements in common. 

• Algorithms min and max find the smallest and largest items in a collection. 

• The Comparator interface provides a means of sorting a Collections elements in an order  other than their natural order. 

Collections method reverseOrder returns a Comparator object that can be used with  sort to sort a collection’s elements in reverse order.

• Algorithm shuffle randomly orders the elements of a List

• Algorithm binarySearch locates an Object in a sorted List

Section 16.8 Stack Class of Package java.util 

• Class Stack extends Vector. Stack method push adds its argument to the top  of the stack. Method pop removes the top element of the stack. Method peek returns a  reference to the top element without removing it. Stack method isEmpty determines  whether the stack is empty. 

Section 16.9 Class PriorityQueue and Interface Queue 

• Interface Queue extends interface Collection and provides additional operations for inserting,  removing and inspecting elements in a queue. 

PriorityQueue implements interface Queue and orders elements by their natural ordering  or by a Comparator object that’s supplied to the constructor.

PriorityQueue method offer inserts an element at the appropriate location based on  priority order. Method poll removes the highest-priority element of the priority queue.  Method peek (peek) gets a reference to the highest-priority element of the priority queue. Method  clear removes all elements in the priority queue. Method size gets the  number of elements in the priority queue. 

Section 16.10 Sets 

• A Set is an unordered Collection that contains no duplicate elements. HashSet stores its elements in a hash table. TreeSet stores its elements in a tree.

• Interface SortedSet extends Set and represents a set that maintains its elements in sorted  order. Class TreeSet implements SortedSet

TreeSet method headSet gets a TreeSet view containing elements that are less than a  specified element. Method tailSet  gets a TreeSet view containing elements that are  greater than or equal to a specified element. Any changes made to these views are made to the  original TreeSet

Section 16.11 Maps

Maps store key–value pairs and cannot contain duplicate keys. HashMaps and  Hashtables store elements in a hash table, and TreeMaps store elements in a tree. 

HashMap takes two type arguments—the type of key and the type of value. 

HashMap method put adds a key–value pair to a HashMap. Method get locates the  value associated with the specified key. Method isEmpty determines if the map is empty. 

HashMap method keySet returns a set of the keys. Map method size returns the  number of key–value pairs in the Map

• Interface SortedMap extends Map and represents a map that maintains its keys in sorted  order. Class TreeMap implements SortedMap

Section 16.12 Properties Class 

• A Properties object is a persistent subclass of Hashtable

• The Properties no-argument constructor creates an empty Properties table. An overloaded  constructor receives a Properties object containing default property values. 

Properties method setProperty specifies the value associated with its key argument.  Method getProperty locates the value of the key specified as an argument. Method  store saves the contents of a Properties object to specified OutputStream. Method load restores the contents of a Properties object from the specified InputStream

Section 16.13 Synchronized Collections 

• Collections from the collections framework are unsynchronized. Synchronization wrappers are provided for collections that can be accessed by multiple threads simultaneously. 

Section 16.14 Unmodifiable Collections 

• Unmodifiable collection wrappers throw UnsupportedOperationExceptions if  attempts are made to modify the collection. 

Section 16.15 Abstract Implementations 

• The collections framework provides various abstract implementations of collection interfaces  from which you can quickly flesh out complete customized implementations.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值