wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

java collections

Total questions: 31

Worksheet time: 16mins

Name
Class
Date
1.

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

2.

Which of these interface is not part of Java’s collection framework?

a)

List

b)

Sorted List

c)

Set

d)

Sorted Map

3.

 What will be the output of the  Java program?

a)

{0, 1, 3, 4}

b)

{0, 1, 2, 4}

c)

{0, 1, 2, 3, 4}

d)

{0, 0, 0, 3, 4}

4.

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

a)

Integer

b)

Double

c)

Boolean

d)

Collections Object

5.

Which of these exceptions is thrown by remover() method?

a)

IOException

b)

SystemException

c)

ObjectNotFoundExeception

d)

IllegalStateException

6.

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

a)

clear();

b)

reset();

c)

delete();

d)

remove();

7.

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

a)

Collection

b)

EventListner

c)

Comparator

d)

Set

e)

List

8.

Which of these is an incorrect form of using method max() to obtain maximum element?

a)

max(Collection c)

b)

max(Collection c, Comparator comp)

c)

max(Comparator comp)

d)

max(List c)

9.

Which of these methods can convert an object into a List?

a)

SetList()

b)

ConvertList()

c)

CopyList()

d)

singletonList()

10.

Which of these is true about unmodifiableCollection() method?

a)

unmodifiableCollection() returns a collection that cannot be modified.

b)

unmodifiableCollection() method is available only for List and Set.

c)

unmodifiableCollection() is defined in Collection class.

d)

None of the mentioned.

11.

Which of these is static variable defined in Collections?

a)

EMPTY_SET

b)

EMPTY_LIST

c)

EMPTY_MAP

d)

All of the mentioned

12.

What implementation of Iterator can traverse a collection in both directions?

a)

Iterator

b)

ListIterator

c)

SetIterator

d)

MapIterator

13.

Which is faster and uses less memory?

a)

ListEnumeration

b)

Iterator

c)

Enumeration

d)

ListIterator

14.

What will be output of given code

a)

a followed by concurrentModification Exception

b)

a b c

c)

a b

d)

a c

15.

Which interface does java.util.Hashtable implement?

a)

Java.util.Map

b)

Java.util.List

c)

Java.util.HashTable

d)

Java.util.Collection

16.

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

17.

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

18.

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

19.

The default capacity of a Vector is:

a)

10

b)

12

c)

8

d)

0

20.

The Comparable interface contains which called?

a)

toCompare

b)

compare

c)

compareTo

d)

compareWith

21.

Find the output

public class TreeMapTest {

public static void main(String args[]) {

Map<Integer, String> m = new TreeMap<Integer, String>();

m.put(11, "audi");

m.put(null, null);

m.put(11, "bmw");

m.put(null, "ferrari");

System.out.println(m.size());

System.out.println(m);

}

a)

Nullpointer exception

b)

compiler error

c)

2

d)

Null value

22.

public class MyClass {

public static void main(String args[]) {

Map<String, String> hashMap = new HashMap<String, String>();

hashMap.put(new String("a"), "audi");

hashMap.put(new String("a"), "ferrari");

System.out.println(hashMap);

}

}

a)

a=audi

b)

a=audi

a=ferrari

c)

a=ferrari

d)

Run time Error

23.

Deque and Queue are derived from

a)

Abstract class

b)

Collection

c)

Abstactcollection

d)

List

24.

What will be output of given code

a)

1 2 3

b)

1 followed by exception

c)

Compile time error

d)

run time error

25.

Which is best suited to a multi-threaded environment?

a)

WeakHashMap

b)

Hashtable

c)

HashMap

d)

ConcurrentHashMap

26.

TreeMap implements?

a)

Dictionary

b)

HashMap

c)

AbstractMap

d)

NavigableMap

27.

Which of these is synchronized?

a)

TreeMap

b)

HashMap

c)

Hashtable

d)

All of the above

28.

TreeMap

a)

doesn't allow null key

b)

allow many null values

c)

Both

d)

allow many null key

29.

How can you sort given HashMap on basis of values

a)

Implement Comparator interface and override its compare method

b)

It is not possible

c)

Implement Comparator interface and override its compareTo method

d)

Implement Comparator interface and override its comparable method

30.

What does Collections.sort internally uses when number of elements are less than 7?

a)

Insertion sort

b)

Merge sort

c)

Quick sort

d)

None

31.

What does Collections.sort internally uses when number of elements are greater than 7?

a)

Insertion sort

b)

Merge sort

c)

Quick sort

d)

None