欢迎来到天天文库
浏览记录
ID:23657958
大小:20.91 KB
页数:15页
时间:2018-11-09
《module7-集合和泛型》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、CopyrightTarenaCorporation,2008.AllrightsreservedModule7-集合和泛型一、选择题:Question1Given:11.publicclassPerson{12.privatename;13.publicPerson(Stringname){14.this.name=name;15.}16.publicinthashCode(){17.return420;18.}19.}Whichistrue?A.ThetimetofindthevaluefromHashMapwithaPersonkeydependsonthesizeofthemap
2、.B.DeletingaPersonkeyfromaHashMapwilldeleteallmapentriesforallkeysoftypePerson.C.InsertingasecondPersonobjectintoaHashSetwillcausethefirstPersonobjecttoberemovedasaduplicate.D.ThetimetodeterminewhetheraPersonobjectiscontainedinaHashSetisconstantanddoesNOTdependonthesizeofthemap.Answer:AQuestion2G
3、iven:11.publicstaticCollectionget(){12.Collectionsorted=newLinkedList();13.sorted.add("B");sorted.add("C");sorted.add("A");14.returnsorted;15.}16.publicstaticvoidmain(String[]args){17.for(Objectobj:get()){18.System.out.print(obj+",");19.}20.}Whatistheresult?A.A,B,C,B.B,C,A,C.Compilationfails.D.Th
4、ecoderunswithnooutput.E.Anexceptionisthrownatruntime.Answer:BCopyrightTarenaCorporation,2008.AllrightsreservedQuestion3Given:1.importjava.util.*;2.publicclassExample{3.publicstaticvoidmain(String[]args){4.//insertcodehere5.set.add(newinteger(2));6.set.add(newinteger(l));7.System.out.println(set);
5、8.}9.}Whichcode,insertedatline4,guaranteesthatthisprogramwilloutput[1,2]?A.Setset=newTreeSet();B.Setset=newHashSet();C.Setset=newSortedSet();D.Listset=newSortedList();E.Setset=newLinkedHashSet();Answer:AQuestion4Given:1.importjava.util.*;2.publicclassPQ{3.publicstaticvoidmain(String[]args){4.Prio
6、rityQueuepq=newPriorityQueue();5.pq.add("carrot");6.pq.add("apple");7.pq.add("banana");8.System.out.println(pq.poll()+":"+pq.peek());9.}10.}Whatistheresult?A.apple:appleB.carrot:appleC.apple:bananaD.banana:appleE.carrot:carrotF.carrot:bananaAnswer:CQuestion5Given:1.importjava.util
7、.*;CopyrightTarenaCorporation,2008.Allrightsreserved2.publicclassWrappedString{3.privateStrings;4.publicWrappedString(Strings){this.s=s;}5.publicstaticvoidmain(String[]args){6.HashSeths=newHashSet();7.W
此文档下载收益归作者所有