Java数据结构与集合类Word文档格式.docx
- 文档编号:16045876
- 上传时间:2022-11-17
- 格式:DOCX
- 页数:14
- 大小:25.49KB
Java数据结构与集合类Word文档格式.docx
《Java数据结构与集合类Word文档格式.docx》由会员分享,可在线阅读,更多相关《Java数据结构与集合类Word文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
∙InterfacesandtheirimplementationsinJava1.2
Collection
|
|__Set(nodupes,nullallowedbasedonimplementation)HashSet
||
||__SortedSet(OrderedSet)TreeSet
|__List(orderedcollection,dupesOK)Vector,ArrayList,LinkedList
Map(key-valuepairs,nullallowedbasedonimplementation)HashTable,HashMap
|
|__SortedMap(OrderedMap)TreeMap
Interface
Description
Abasicinterfacethatdefinestheoperationsthatalltheclassesthatmaintaincollectionsofobjectstypicallyimplement.
Set
ExtendsCollection,setsthatmaintainuniqueelements.Setinterfaceisdefinedintermsoftheequalsoperation
SortedSet
ExtendsSet,maintaintheelementsinasortedorder
List
ExtendsCollection,maintainelementsinasequentialorder,duplicatesallowed.
Map
Abasicinterfacethatdefinesoperationsthatclassesthatrepresentmappingsofkeystovaluestypicallyimplement
SortedMap
ExtendsMapformapsthatmaintaintheirmappingsinkeyorder.
∙Classesthatimplementtheinterfacesusedifferentstoragemechanisms.
1.Arrays
Indexedaccessisfaster.Makesinsertion,deletionandgrowingthestoremoredifficult.
2.LinkedList
Supportsinsertion,deletionandgrowingthestore.Butindexedaccessisslower.
3.Tree
Supportsinsertion,deletionandgrowingthestore.Indexedaccessisslower.Butsearchingisfaster.
4.Hashing
However,requirestheuseofuniquekeysforstoringdataelements.
DataStructures
Interfaces
HashTable
HashSet
HashMap
HashTable
ResizableArray
ArrayList
Vector
BalancedTree
TreeSet
TreeMap
LinkedList
LinkedList
Someoftheoperationsinthecollectioninterfacesareoptional,meaningthattheimplementingclassmaychoosenottoprovideaproperimplementationofsuchanoperation.Insuchacase,anUnsupportedOperationExceptionisthrownwhenthatoperationisinvoked.
Methods
BasicOperations
intsize();
booleanisEmpty();
booleancontains(Objectelement);
booleanadd(Objectelement);
booleanremove(Objectelement);
Usedtoqueryacollectionaboutitscontents,andadd/removeelements.
Theadd()andremove()methodsreturntrueifthecollectionwasmodifiedasaresultoftheoperation.Thecontains()methodchecksformembership.
BulkOperations
booleancontainsAll(Collectionc);
booleanaddAll(Collectionc);
booleanremoveAll(Collectionc);
booleanretainAll(Collectionc);
voidclear();
Performonacollectionasasingleunit.
Operationsareequivalentofsetlogiconarbitrarycollections(notjustsets).TheaddAll(),removeAll(),clear()andretainAll()methodsaredestructive.
ArrayOperations
Object[]toArray();
Object[]toArray(Objecta[]);
ThesemethodscombinedwithArrays.asList()methodprovidethebridgebetweenarraysandcollections.
Iterators
Iteratoriterator();
Iteratorisaninterfacewhichhasthesemethods.
booleanhasNext();
Objectnext();
voidremove();
Returnsaniterator,toiteratethecollection.
Theremove()methodistheonlyrecommendedwaytoremoveelementsfromacollectionduringtheiteration.
Nonewmethodsdefined.
Theadd()methodreturnsfalse,iftheelementisalreadyintheSet.Noexceptionsarethrown.
ElementAccessbyIndex
Objectget(intindex);
Objectset(intindex,O
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 数据结构 集合