4. Java集合知识测试- 副本

发布时间 : 星期一 文章4. Java集合知识测试- 副本更新完毕开始阅读

b) java.util.Collection c) java.util.List d) java.util.Set

35. List集合的遍历方式有如下哪几种 ( ABC )

a) Iterator迭代器实现 b) 增强for循环实现

c) get()和size()方法结合实现 d) get()和length()方法结合实现

36. 题示代码的功能为:对于一个存放Person对象的ArrayList进行循

环遍历。并输出每个Person对象的idCard和userName。 public class Person{ private Long idCard; pirvate String userName;

//以下是getter和setter方法 //省略 }

List list=new ArrayList(); Person p1=new Person();

p1.setIdCard(new Long(1001));

p1.setUserName(“terry”); Person p2=new Person(); p2.setIdCard(new Long(1002)); p2.setUserName(“tom”); list.add(p1); list.add(p2);

for( 位置① ){ System.out.println(person.getIdCard()+”:”+person.getUserName()); }

那么位置①处的代码为 a) List list:person b) List list:Person c) Person person:List d) Person person:list D

37. 下面代码的运行结果是( D )

ArrayList al = new ArrayList(); al.add(“a”); al.add(“b”); al.add(“c”);

Iterator it = al.iterator(); while(it.hasNext()){

String s = (String)it.next(); if(s.equals(“c”)){ al.add(“c1”); } }

System.out.println(al); a) [a,b,c] b) [c1]

c) [a,b,c,c1]

d) 抛出ConcurrentModificationException异常

38. 下面关于泛型的说法不正确的是( )

a) 泛型的具体确定时间可以是在定义方法的时候 b) 泛型的具体确定时间可以是在创建对象的时候

c) 泛型的具体确定时间可以是在继承父类定义子类的时候 d) 泛型就是Object类型 B/d

39. 下面关于Collection 和 Collections的区别错误的是( )

a) Collections是集合顶层接口

b) Collection是针对Collections集合操作的工具类 c) List、Set、Map都继承自Collection接口

d) Collections是针对Collection集合操作的工具类

B/AB

40. 关于泛型的说法正确的是( )

a) 泛型是JDK1.5出现的新特性 b) 泛型是一种安全机制

c) 使用泛型避免了强制类型转换 d) 使用泛型必须进行强制类型转换

BC/ABC

联系合同范文客服:xxxxx#qq.com(#替换为@)