Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Collections

Total questions: 30

Worksheet time: 23mins

Name
Class
Date
1.

-Contains no duplicate elements.

-Can contain at most one Null value.

-Elements are not key-value pairs.

-Accessing an element can be almost as fast as performing a similar operation on an array.


Which of these classes provides the specified features?

a)

LinkedList

b)

TreeMap

c)

HashSet

d)

LinkedHashMap

e)

HashMap

2.

Which of the following statement about Set is true?

a)

A HashSet cannot have a null value.

b)

Set allows duplicate values.

c)

Set allows null values but only single occurrence.

d)

Set extends the Java.util.collection interface.

3.
a)

{1=C, 2=JavaEE, 4=Python, 3=PHP}

b)

{1=C, 2=JavaSE, 3=Python, 4=PHP}

c)

{1=C, 2=JavaEE, 3=Python, 4=PHP}

d)

{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}

e)

NullPointerException

4.
a)

{null=null, a=null, b=JavaSE, c=PHP, d=Python}

b)

{a=null, b=JavaSE, c=PHP, d=Python}

c)

{b=JavaSE, c=PHP, d=Python}

d)

Compilation Fails

5.
a)

4

b)

5

c)

6

d)

12

6.

-Entries are not organized as key/value pairs.

-Duplicate entries are rejected.

Which interface of the java.util package offers the specified behavior?

a)

List

b)

Map

c)

Set

d)

None of the above

7.
a)

[Computer, Network, Networks, Programming, Security]

b)

[Computer, Programming, Network, Networks, Programming, Security]

c)

[Computer, Programming, Computer, Networks, Network, Security]

d)

[Computer, Networks, Network, Programming, Security]

8.

Which of the following is/are correct statements?

a)

HashSet class implements the Set interface

b)

HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.

c)

HashSet permits to have a single null value.

d)

HashMap does not allow duplicate keys however it allows to have duplicate values.

e)

HashMap and HashSet are threadsafe

9.

List listNames = new ArrayList();

listNames.add("Tom");

listNames.add("Mary");

listNames.add("Peter");


String name2 = (String) listNames.get(1);

System.out.println(name2);

What is the output of the above code

a)

Tom

b)

Mary

c)

Peter

d)

raises Exception

10.

Which of the following statement is not True about Generics in java?

a)

Generics are features of the Java programming language that allow programmers to write parameterized code.

b)

With generics, the compiler can not detect violations at compile time, thus eliminating potential bugs.

c)

Due to the demand of safer code, generics were added to the Java programming language.

d)

generics allow you to write generic code

e)

Stronger type checks at compile time

11.

When do we use sets in java program?

a)

To allow null and duplicate elements

b)

You want to store elements distinctly without duplication, or unique elements.

c)

to allow t contain duplicate keys and each key can map to at most one value

d)

To perform lookups by keys

12.

What will happen if an element already present in the Set is added again?

a)

Run time error will be generated

b)

No error, the element will be added once again to the set

c)

Compile time error

d)

A boolean value of false will be returned, and the value will not be added to the Set

13.

What is Collection in Java?

a)

A group of objects

b)

A group of classes

c)

A group of interfaces

d)

None of the mentioned

14.

Which of these return type of hasNext() method of an iterator?

a)

Integer

b)

Double

c)

Boolean

d)

Collections Object

15.

Which of these methods deletes all the elements from invoking collection?

a)

clear();

b)

reset();

c)

delete();

d)

remove();

16.

Which of these interface declares core method that all collections will have?

a)

Collection

b)

EventListner

c)

Comparator

d)

Set

e)

List

17.

Which of these is static variable defined in Collections?

a)

EMPTY_SET

b)

EMPTY_LIST

c)

EMPTY_MAP

d)

All of the mentioned

18.

What will be output of given code

a)

a followed by concurrentModification Exception

b)

a b c

c)

a b

d)

a c

19.

Which interface does java.util.Hashtable implement?

a)

Java.util.Map

b)

Java.util.List

c)

Java.util.HashTable

d)

Java.util.Collection

20.

You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order.

Which interface provides that capability?

a)

java.util.Map

b)

java.util.Set

c)

java.util.List

d)

java.util.Collection

21.

Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?

a)

java.util.HashSet

b)

java.util.LinkedHashSet

c)

java.util.List

d)

java.util.ArrayList

22.

What will be output of given code

a)

1 2 3

b)

1 followed by exception

c)

Compile time error

d)

run time error

23.

Lists does not allow duplicates (True/False)

a)

False

b)

True

24.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

25.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

26.

try block may or may not contains catch blocks

a)

True

b)

False

27.

Which of these keywords is not a part of exception handling?

a)

try

b)

finally

c)

thrown

d)

catch

28.

java.lang.NullPointerException is a

a)

Error

b)

runtime exception

c)

Compile time exception

d)

None

29.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

30.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException