栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java程序设计练习题7集合与泛型

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java程序设计练习题7集合与泛型

判断题 R1-1

在JAVA的集合框架中,Map接口是自Collection接口继承而来。

T

F

单选题 R2-1

分数 2

Which statement is true for the class java.util.ArrayList?

A.

The elements in the collection are guaranteed to be unique.

B.

The collection is guaranteed to be immutable.

C.

The elements in the collection are ordered.

D.

The elements in the collections are guaranteed to be synchronized


R2-2

分数 2

Which of the interfaces below is a collection as duplicating, ordered, unsorted?

A.

Collection

B.

ArrayList

C.

HashMap

D.

TreeSet


R2-3

分数 2

下面哪个Set是根据内容排序的?

A.

HashSet

B.

LinkedHashSet

C.

AbstractSet

D.

TreeSet


R2-4

分数 2

Java的集合框架中重要的接口java.util.Collection定义了许多方法。选项中哪个方法不是Collection接口所定义的?(     )

A.

compareTo(Object obj)

B.

boolean containsAll(Collection c)

C.

boolean remove(Object obj)

D.

int size()


R2-5

分数 2

Given code below:

    Set s = new HashSet();
    s.add(new Integer(1));
    s.add(new Integer(2));
    s.add(new Integer(1));

Which statement below is correct?

A.

It compiles but exception raises at line 4, for 1 is already in the set.

B.

It complies and there are three elements in s.

C.

It does not compile.

D.

It compiles, but only two elements left in s.


R2-6

分数 2

在Java中,关于HashMap类的描述,以下选项错误的是

A.

HashMap使用键/值得形式保存数据

B.

HashMap允许将null用作值

C.

HashMap允许将null用作键

D.

HashMap 能够保证其中元素的顺序


R2-7

分数 2

在Java中,( )类可用于创建链表数据结构的对象

A.

Collection

B.

HashMap

C.

LinkedList

D.

ArrayList


R2-8

分数 2

Given code below:

    List ls = new ArrayList();
    List lo = ls;
    lo.add(new Object());
    String s = ls.get(0);
 

Which statement below is correct?

A.

It compiles but exception raises at line 4

B.

It compiles but exception raises at line 2

C.

It compiles but exception raises at line 3

D.

It does not compile


R2-9

分数 2

Given code below:

    Set s = new HashSet();
    s.add(1);
    s.add(2);
    s.add(1);

Which statement below is correct?

A.

It compiles but exception raises at line 2, for 1 is not an objects of Integer

B.

It compiles but exception raises at line 4, for 1 is already in the set

C.

It compiles, but only two element left in s

D.

It does not compile because 1 and 2 are not objects of Integer


R2-10

分数 2

About Java containers, which statement below is NOT correct?

A.

ArrayList holds the elements in a particular sequence.

B.

TreeSet cannot have any duplicate elements.

C.

List, Set and Map, they all have stream() interface.

D.

LinkedList holds the elements in a particular sequence.


R2-11

分数 2

Java中,要对一个类实现for( : )形式的遍历,则该类必须实现下列哪一个接口?

A.

Comparable

B.

Cloneable

C.

Iterable

D.

Iterator


R2-12

分数 2

Which of the interfaces below is a collection as duplicating, ordered, unsorted?

A.

Map

B.

Set

C.

List

D.

Collection


R2-13

分数 2

list是一个ArrayList的对象,哪个选项的代码填写到//todo delete处,可以在Iterator遍历的过程中正确并安全的删除一个list中保存的对象?(     )

Iterator it = list.iterator();
        int index = 0;
        while (it.hasNext()){
              Object obj = it.next();
              if (needDelete(obj)) { //needDelete返回boolean,决定是否要删除
                   //todo delete
               }
              index ++;
        }

A.

list.remove(it.next());

B.

it.remove();

C.

list.remove(obj);

D.

list.remove(index);


R2-14

分数 2

Given code below:

Set s = new HashSet();
s.add(new Integer(1));
s.add(new Integer(2));
s.add(new Integer(1));

Which statement below is correct?

A.

It compiles but exception raises at line 4, for 1 is already in the set.

B.

It does not compile.

C.

It complies and there are three elements in s.

D.

It compiles, but only two elements left in s.


R2-15

分数 2

For code below:

ArrayList a = new ArrayList();
ArrayList b = new ArrayList();

Which statement below is NOT correct?

A.

a instanceof ArrayList is true

B.

a.getClass().equals(b.getClass()) is true

C.

a.getClass() == b.getClass() is false

D.

a.getClass() == b.getClass() is true


R2-16

分数 2

Vector a = new Vector();
a.addElement(10);
System.out.println(a.elementAt(0));

A.

Prints some garbage.

B.

Prints 10.

C.

Compilation error at line 3.

D.

Prints 11.


R2-17

分数 2

Given code below:

List l1 = new ArrayList<>();
ArrayList l2 = new ArrayList<>();
System.out.println(l1.getClass() == l2.getClass());

The result of compilation and running in Java 8 is:

A.

It compiles and exception raises at run-time

B.

It compiles and prints out true

C.

It does not compile

D.

It compiles and prints out false


R2-18

分数 1

使用Iterator时,判断是否存在下一个元素可以使用以下哪个方法?()

A.

hash()

B.

hasNext()

C.

next()

D.

hasPrevious()


R2-19

分数 2

Which most closely matches a description of a Java Map?

A.

A class for containing unique vector elements

B.

An interface that ensures that implementing classes cannot contain duplicate keys

C.

A vector of arrays for a 2D geographic representation

D.

A class for containing unique array elements


R2-20

分数 2

下面哪个Set是按照插入顺序排序的?

A.

AbstractSet

B.

HashSet

C.

LinkedHashSet

D.

TreeSet


R2-21

分数 2

About Java containers, which statement below is NOT correct?

A.

Map has group of key-value object pairs

B.

Iterator can deal with List, Set and Map

C.

Set cannot have any duplicate elements

D.

List holds the elements in a particular sequence


R2-22

分数 2

Given list an object of ArrayList, which code below for //todo delete can remove an element in the list correctly and safely?

 
        Iterator it = list.iterator();
        int index = 0;
        while (it.hasNext()){
              Object obj = it.next();
              if (needDelete(obj)) { // returns Boolean for removing or not
                   //todo delete
              }
              index ++;
        }

A.

it.remove();

B.

list.remove(it.next());

C.

list.remove(index);

D.

list.remove(obj);


R2-23

分数 2

下面哪个Map是排序的?

A.

LinkedHashMap

B.

Hashtable

C.

TreeMap

D.

WeakHashMap

E.

HashMap

填空题
转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号