资源描述:
《Java语言程序设计10E LiangPPT习题案例20slide.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1Chapter20Lists,Stacks,Queues,andPriorityQueues2ObjectivesToexploretherelationshipbetweeninterfacesandclassesintheJavaCollectionsFrameworkhierarchy(§20.2).TousethecommonmethodsdefinedintheCollectioninterfaceforoperatingcollections(§20.2).TousetheIteratorinterfacetotraversetheelementsinacollection(§
2、20.3).Touseafor-eachlooptotraversetheelementsinacollection(§20.3).ToexplorehowandwhentouseArrayListorLinkedListtostoreelements(§20.4).TocompareelementsusingtheComparableinterfaceandtheComparatorinterface(§20.5).TousethestaticutilitymethodsintheCollectionsclassforsorting,searching,shufflinglists,and
3、findingthelargestandsmallestelementincollections(§20.6).TodevelopamultiplebouncingballsapplicationusingArrayList(§20.7).TodistinguishbetweenVectorandArrayListandtousetheStackclassforcreatingstacks(§20.8).ToexploretherelationshipsamongCollection,Queue,LinkedList,andPriorityQueueandtocreatepriorityqu
4、euesusingthePriorityQueueclass(§20.9).Tousestackstowriteaprogramtoevaluateexpressions(§20.10).3JavaCollectionFrameworkhierarchyAcollectionisacontainerobjectthatholdsagroupofobjects,oftenreferredtoaselements.TheJavaCollectionsFrameworksupportsthreetypesofcollections,namedlists,sets,andmaps.4JavaColl
5、ectionFrameworkhierarchy,cont.SetandListaresubinterfacesofCollection.5TheCollectionInterfaceTheCollectioninterfaceistherootinterfaceformanipulatingacollectionofobjects.6TheListInterfaceAliststoreselementsinasequentialorder,andallowstheusertospecifywheretheelementisstored.Theusercanaccesstheelements
6、byindex.7TheListInterface,cont.8TheListIterator9ArrayListandLinkedListTheArrayListclassandtheLinkedListclassareconcreteimplementationsoftheListinterface.Whichofthetwoclassesyouusedependsonyourspecificneeds.Ifyouneedtosupportrandomaccessthroughanindexwithoutinsertingorremovingelementsfromanyplaceoth
7、erthantheend,ArrayListoffersthemostefficientcollection.If,however,yourapplicationrequirestheinsertionordeletionofelementsfromanyplaceinthelist,youshouldchooseLinkedList.Alistcangroworshrinkdynamically.Anarr