资源描述:
《外文文献-high-level programming language java collections of objects高级编程语言 java之集合与对象》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、毕业设计外文文献原文及译文High-levelprogramminglanguageJavaCollectionsofObjects高级编程语言Java之集合与对象电子与计算机科学技术系学生姓名:学号:网络工程系别:专业:指导教师:2015年5月High-levelprogramminglanguageJavaCollectionsofObjectsIt’safairlysimpleprogramthathasonlyafixedquantityofobjectswithknownlifetimes.Ingeneral,yourprogramswillalwaysbecreatingnewo
2、bjectsbasedonsomecriteriathatwillbeknownonlyatthetimetheprogramisrunning.Youwon’tknowuntilruntimethequantityoreventheexacttypeoftheobjectsyouneed.Tosolvethegeneralprogrammingproblem,youneedtobeabletocreateanynumberofobjects,anytime,anywhere.Soyoucan’trelyoncreatinganamedreferencetoholdeachoneofyour
3、objects:MyObjectmyReference;sinceyou’llneverknowhowmanyoftheseyou’llactuallyneed.Mostlanguagesprovidesomewaytosolvethisratheressentialproblem.Javahasseveralwaystoholdobjects(orrather,referencestoobjects).Thebuilt-intypeisthearray,whichhasbeendiscussedbefore.Also,theJavautilitieslibraryhasareasonabl
4、ycompletesetofcontainerclasses(alsoknownascollectionclasses,butbecausetheJava2librariesusethenameCollectiontorefertoaparticularsubsetofthelibrary,Ishallalsousethemoreinclusiveterm“container”).Containersprovidesophisticatedwaystoholdandevenmanipulateyourobjects.ArraysHoldingobjectsisthefocusofthisch
5、apter,andanarrayisjustonewaytoholdobjects.Butthereareanumberofotherwaystoholdobjects,sowhatmakesanarrayspecial?Therearetwoissuesthatdistinguisharraysfromothertypesofcontainers:efficiencyandtype.ThearrayisthemostefficientwaythatJavaprovidestostoreandrandomlyaccessasequenceofobjectreferences.Thearray
6、isasimplelinearsequence,whichmakeselementaccessfast,butyoupayforthisspeed:whenyoucreateanarrayobject,itssizeisfixedandcannotbechangedforthelifetimeofthatarrayobject.Youmightsuggestcreatinganarrayofaparticularsizeandthen,ifyourunoutofspace,creatinganewoneandmovingallthereferencesfromtheoldonetothene
7、wone.ThisisthebehavioroftheArrayListclass,which第9页共10页willbestudiedlaterinthischapter.However,becauseoftheoverheadofthisflexibility,anArrayListismeasurablylessefficientthananarray.InC++,thevectorcontainercl