wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Collections Framework in java

Total questions: 46

Worksheet time: 24mins

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.

-Entries are organized as key/value pairs.

-Duplicate entries replace old entries.

-Entries are sorted using a Comparator or the Comparable interface.

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

a)

List

b)

Map

c)

Set

d)

SortedSet

e)

SortedMap

4.
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

5.
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

6.
a)

4

b)

5

c)

6

d)

12

7.

-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

8.
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]

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.

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

11.

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

a)

List

b)

Sorted List

c)

Set

d)

Sorted Map

12.

 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}

13.

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

a)

Integer

b)

Double

c)

Boolean

d)

Collections Object

14.

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

a)

clear();

b)

reset();

c)

delete();

d)

remove();

15.

What is a collection in Java?

a)

A command for storing and manipulating a group of objects

b)

A set of classes and interfaces that provides a ready-made architecture

c)

A unified architecture for storing and manipulating a group of objects

d)

A group of individual objects represented as a single unit

16.

What are the advantages of the Java collection framework?

a)

Consistent API, reduces programming effort, and improves performance

b)

Provides a basic set of interfaces and methods for all collections

c)

Allows for searching, sorting, insertion, manipulation, and deletion

d)

Defines a common interface and correlation among different collections

17.

What is a framework in Java?

a)

A set of classes and interfaces that provides a ready-made architecture

b)

A unified architecture for storing and manipulating a group of objects

c)

A framework for storing and manipulating a group of objects

d)

A group of individual objects represented as a single unit

18.

What is the purpose of the List interface in Java?

a)

To store and maintain an ordered collection

b)

To provide index-based methods for manipulating elements

c)

To accommodate duplicate elements and store null elements

d)

To iterate the list in both forwards and backwards directions

19.

Which of the following is an implementation class of the List interface?

a)

ArrayList

b)

StringList

c)

Stack

d)

Vector

20.

What is the difference between a class and an interface in Java?

a)

A class is a blueprint for objects, while an interface is a blueprint for classes

b)

A class can have both methods and variables, while an interface can only have methods

c)

A class represents a set of properties or methods common to all objects of one type

d)

An interface specifies what a class must do, not how it does it

21.

Which method is used to add an object to a collection?

a)

add(Object)

b)

addAll(Collection)

c)

clear()

d)

contains(Object)

22.

What does the remove(Object) method do?

a)

Removes an object from the collection

b)

Removes the element at a specific index in the List

c)

Returns true if the collection contains the specified element

d)

Compares the specified object with the collection for equality

23.

What is the purpose of the Set interface in Java?

a)

To provide an ordered collection

b)

To store and maintain a group of objects

c)

To implement a mathematical set

d)

To allow the inclusion of duplicate elements

24.

Which of the following is an implementation class of the Set interface?

a)

HashSet

b)

LinkedHashSet

c)

ArrayList

d)

LinkedList

25.

What is the main difference between List and Set interfaces?

a)

List is an ordered sequence, while Set is an unordered sequence

b)

List allows the inclusion of duplicate elements, while Set does not

c)

List allows position access to elements, while Set does not

d)

List can store multiple null elements, while Set can only store one

26.

What is the purpose of the add(int index, Object) method in List?

a)

To add an element at the end of the List

b)

To add an element at a specific index in the List

c)

To update an element at a specific index in the List

d)

To remove an element from the List

27.

How can you iterate over a List in Java?

a)

Using a basic for loop and the get() method

b)

Using a while loop and the get() method

c)

Using an advanced for loop

d)

All of the above

28.

What is the advantage of using the remove(int index) method in List?

a)

It removes an object from the List

b)

It removes the element at a specific index in the List

c)

It returns true if the collection contains the specified element

d)

It compares the specified object with the collection for equality

29.

What is the purpose of the clear() method in List?

a)

To add an object to the collection

b)

To remove all elements from the collection

c)

To check if the collection contains the specified element

d)

To return the number of elements in the collection

30.

What is the output of this code?

a)

[SPARK, Arden, University, IS]

b)

[Arden, University, IS, SPARK]

c)

[SPARK, University, Arden, IS]

d)

[SPARK, IS, University, Arden]

31.

What will be the results of running this code?

a)

Showing elements in forward direction

index:0 value: Jaguar

index:1 value:Porcshe

index:2 value:BMW

index:3 value: Ferrari

Showing elements in backward direction

index:3 value: BMW

index:2 value: Ferrari

index:1 value:Porsche

index:0 value:Jaguar

b)

Showing elements in forward direction

index:1 value:Ferrari

index:2 value:Porcshe

index:3 value:BMW

index:4 value:Jaguar

Showing elements in backward direction

index:1 value:Jaguar

index:2 value:BMW

index:3 value:Porsche

index:4 value:Ferrari

c)

Showing elements in forward direction

index:0 value:Ferrari

index:1 value:Porcshe

index:2 value:BMW

index:3 value:Jaguar

Showing elements in backward direction

index:3 value:Jaguar

index:2 value:BMW

index:1 value:Porsche

index:0 value:Ferrari

32.

-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

33.

Which of the following statements are true with respect to sets as objects of Hashset?

a)

Set is always an ordered group of objects.

b)

Set allows duplicate objects.

c)

Set does not allow duplicate objects.

d)

Set supports iterators.

34.

Which of the following interfaces declares a core method that all collections will have?

a)

EventListener

b)

Comparator

c)

Set

d)

Collection

35.

Which of the following statements are correct with respect to a Map in Java?

a)

A map can have iterators for accessing its elements.

b)

The elements of a map are accessed by the respective keys.

c)

Maps are the same as a SortedSet.

d)

None of these.

36.

Which of the following interfaces must contain a unique element?

a)

List

b)

Set

c)

Array

d)

Collection

37.

Which of the following statements are correct with respect to a List in Java?

a)

A List is implemented in the "first-in, first-out" (FIFO) order.

b)

A List is implemented in the "first-in, last-out" (FILO) order.

c)

Lists support duplicate items.

d)

None of these.

38.

We need to access elements frequently by using index...

Which one is better solution?

a)

Set

b)

List

c)

Map

39.

We want store data in form Key and Value... Whic one is better solution?

a)

Set

b)

List

c)

Map

40.

We want to create collection of unique elements without duplicates... Which one is better solution?

a)

Set

b)

List

c)

Map

41.

Contains no duplicate elements

Elements are not key-value pairs

Always unique elements

a)

LinkedList

b)

TreeMap

c)

HashSet

d)

HashMap

42.

What does it mean for a list to be "dynamic" in ArrayList?

a)

You can easily add and remove elements

b)

It may contain multiple types of values

c)

It has a set size once it has been created

d)

You can access it from anywhere in the program

43.

Collection Framework Comes under which package?

a)

java.lang

b)

java.io

c)

java.util

d)

java.applet

44.

Which option is correct in the following collection interface hierarchy?

a)

List,Set,Queue

b)

List,Set,Map

c)

List,Map

d)

Map,Queue,Sey

45.
____ is the process of arranging a series of objects in some logical order.
a)
Passing
b)
Organizing
c)
Sorting
d)
Sending
46.

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.