module7-集合和泛型

module7-集合和泛型

ID:23657958

大小:20.91 KB

页数:15页

时间:2018-11-09

module7-集合和泛型_第1页
module7-集合和泛型_第2页
module7-集合和泛型_第3页
module7-集合和泛型_第4页
module7-集合和泛型_第5页
资源描述:

《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

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。