Download presentation
Presentation is loading. Please wait.
1
Chapter10 Collections
2
What Is a Collection? ▲ a poker hand (a collection of cards),
● A collection is simply an object that groups multiple elements into a single unit. ● sometimes called a container ● Collections are used to store, retrieve and manipulate data, and to transmit data from one method to another. ● Collections typically represent data items that form a natural group, like ▲ a poker hand (a collection of cards), ▲ a mail folder (a collection of letters), ▲ a telephone directory (a collection of name-to-phone-number mappings). retrieve retrieve[简明英汉词典] [riˈtri:v] vt. 1 寻回, 找回 2 恢复, 挽回 3 检索(储存的信息) 4 使某事物恢复旺盛状态 vt. & vi. (指经过训练的狗)找到并衔回(被打死或打伤的鸟等) poker poker[简明英汉词典] [ˈpəukə] n. 1 拨火铁棒 2 纸牌; 扑克
3
Collections Framework
● A collections framework is a unified architecture for representing and manipulating collections.
4
All collections frameworks contain three things
Interfaces Implementations Algorithms
5
Interfaces: abstract data types representing collections. Interfaces allow collections to be manipulated independently of the details of their representation. In object-oriented languages like Java, these interfaces generally form a hierarchy. general form general form[简明英汉词典] (普)通式 词条指正 - Google 搜索
6
Implementations: concrete implementations of the collection interfaces. In essence, these are reusable data structures. In essence in essence[简明英汉词典] 本质上;大体上;其实 词条指正 - Google 搜索 concrete concrete[简明英汉词典] [ˈkɔnkri:t] adj. 1 实体的, 有形的 2 确实的, 明确的, 确定的 词条指正 - Google 搜索
7
Algorithms: methods that perform useful computations, like searching and sorting, on objects that implement collection interfaces. These algorithms are said to be polymorphic because the same method can be used on many different implementations of the appropriate collections interface. In essence, algorithms are reusable functionality. polymorphic polymorphic[简明英汉词典] [ˌpɔliˈmɔ:fik] adj. 多形的,多态的,多形态的 词条指正 - Google 搜索
8
the Benefits of a Collections Framework
● It reduces programming effort: ● It increases program speed and quality: ● It allows interoperability among unrelated APIs: ● It reduces the effort to learn and use new APIs: ● It reduces effort to design new APIs: ● It fosters software reuse: By providing useful data structures and algorithms foster foster[简明英汉词典] [ˈfɔstə] vt. 培养, 促进 vt. & vi. 收养, 养育 词条指正 - Google 搜索
9
The core collection interfaces
● The core collection interfaces are the interfaces used to manipulate collections, and to pass them from one method to another. ● The basic purpose of these interfaces is to allow collections to be manipulated independently of the details of their representation. ● The core collection interfaces are the heart and soul of the collections framework.
10
The core collections interfaces are shown below:
11
AbstractSequentialList
Collections Framework Collection List Set Map SortedSet SortedMap ArrayList LinkedList HashSet TreeSet HashMap TreeMap AbstractList AbstractSet AbstractMap AbstractSequentialList AbstractCollection
12
Collection The Collection interface is the root of the collection hierarchy. A Collection represents a group of objects, known as its elements. Some Collection implementations allow duplicate elements and others do not. Set A Set is a collection that cannot contain duplicate elements. List A List is an ordered collection (sometimes called a sequence). Lists can contain duplicate elements. Map A Map is an object that maps keys to values. Maps cannot contain duplicate keys: Each key can map to at most one value.
13
*参见程序运行
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.