WorksheetsCollections Framework in java
Total questions: 46
Worksheet time: 24mins
-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?
LinkedList
TreeMap
HashSet
LinkedHashMap
HashMap
Which of the following statement about Set is true?
A HashSet cannot have a null value.
Set allows duplicate values.
Set allows null values but only single occurrence.
Set extends the Java.util.collection interface.
-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?
List
Map
Set
SortedSet
SortedMap
{1=C, 2=JavaEE, 4=Python, 3=PHP}
{1=C, 2=JavaSE, 3=Python, 4=PHP}
{1=C, 2=JavaEE, 3=Python, 4=PHP}
{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}
NullPointerException
{null=null, a=null, b=JavaSE, c=PHP, d=Python}
{a=null, b=JavaSE, c=PHP, d=Python}
{b=JavaSE, c=PHP, d=Python}
Compilation Fails
4
5
6
12
-Entries are not organized as key/value pairs.
-Duplicate entries are rejected.
Which interface of the java.util package offers the specified behavior?
List
Map
Set
None of the above
[Computer, Network, Networks, Programming, Security]
[Computer, Programming, Network, Networks, Programming, Security]
[Computer, Programming, Computer, Networks, Network, Security]
[Computer, Networks, Network, Programming, Security]
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
Tom
Mary
Peter
raises Exception
What is Collection in Java?
A group of objects
A group of classes
A group of interfaces
None of the mentioned
Which of these interface is not part of Java’s collection framework?
List
Sorted List
Set
Sorted Map
What will be the output of the Java program?
{0, 1, 3, 4}
{0, 1, 2, 4}
{0, 1, 2, 3, 4}
{0, 0, 0, 3, 4}
Which of these return type of hasNext() method of an iterator?
Integer
Double
Boolean
Collections Object
Which of these methods deletes all the elements from invoking collection?
clear();
reset();
delete();
remove();
What is a collection in Java?
A command for storing and manipulating a group of objects
A set of classes and interfaces that provides a ready-made architecture
A unified architecture for storing and manipulating a group of objects
A group of individual objects represented as a single unit
What are the advantages of the Java collection framework?
Consistent API, reduces programming effort, and improves performance
Provides a basic set of interfaces and methods for all collections
Allows for searching, sorting, insertion, manipulation, and deletion
Defines a common interface and correlation among different collections
What is a framework in Java?
A set of classes and interfaces that provides a ready-made architecture
A unified architecture for storing and manipulating a group of objects
A framework for storing and manipulating a group of objects
A group of individual objects represented as a single unit
What is the purpose of the List interface in Java?
To store and maintain an ordered collection
To provide index-based methods for manipulating elements
To accommodate duplicate elements and store null elements
To iterate the list in both forwards and backwards directions
Which of the following is an implementation class of the List interface?
ArrayList
StringList
Stack
Vector
What is the difference between a class and an interface in Java?
A class is a blueprint for objects, while an interface is a blueprint for classes
A class can have both methods and variables, while an interface can only have methods
A class represents a set of properties or methods common to all objects of one type
An interface specifies what a class must do, not how it does it
Which method is used to add an object to a collection?
add(Object)
addAll(Collection)
clear()
contains(Object)
What does the remove(Object) method do?
Removes an object from the collection
Removes the element at a specific index in the List
Returns true if the collection contains the specified element
Compares the specified object with the collection for equality
What is the purpose of the Set interface in Java?
To provide an ordered collection
To store and maintain a group of objects
To implement a mathematical set
To allow the inclusion of duplicate elements
Which of the following is an implementation class of the Set interface?
HashSet
LinkedHashSet
ArrayList
LinkedList
What is the main difference between List and Set interfaces?
List is an ordered sequence, while Set is an unordered sequence
List allows the inclusion of duplicate elements, while Set does not
List allows position access to elements, while Set does not
List can store multiple null elements, while Set can only store one
What is the purpose of the add(int index, Object) method in List?
To add an element at the end of the List
To add an element at a specific index in the List
To update an element at a specific index in the List
To remove an element from the List
How can you iterate over a List in Java?
Using a basic for loop and the get() method
Using a while loop and the get() method
Using an advanced for loop
All of the above
What is the advantage of using the remove(int index) method in List?
It removes an object from the List
It removes the element at a specific index in the List
It returns true if the collection contains the specified element
It compares the specified object with the collection for equality
What is the purpose of the clear() method in List?
To add an object to the collection
To remove all elements from the collection
To check if the collection contains the specified element
To return the number of elements in the collection
What is the output of this code?
[SPARK, Arden, University, IS]
[Arden, University, IS, SPARK]
[SPARK, University, Arden, IS]
[SPARK, IS, University, Arden]
What will be the results of running this code?
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
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
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
-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?
LinkedList
TreeMap
HashSet
LinkedHashMap
HashMap
Which of the following statements are true with respect to sets as objects of Hashset?
Set is always an ordered group of objects.
Set allows duplicate objects.
Set does not allow duplicate objects.
Set supports iterators.
Which of the following interfaces declares a core method that all collections will have?
EventListener
Comparator
Set
Collection
Which of the following statements are correct with respect to a Map in Java?
A map can have iterators for accessing its elements.
The elements of a map are accessed by the respective keys.
Maps are the same as a SortedSet.
None of these.
Which of the following interfaces must contain a unique element?
List
Set
Array
Collection
Which of the following statements are correct with respect to a List in Java?
A List is implemented in the "first-in, first-out" (FIFO) order.
A List is implemented in the "first-in, last-out" (FILO) order.
Lists support duplicate items.
None of these.
We need to access elements frequently by using index...
Which one is better solution?
Set
List
Map
We want store data in form Key and Value... Whic one is better solution?
Set
List
Map
We want to create collection of unique elements without duplicates... Which one is better solution?
Set
List
Map
Contains no duplicate elements
Elements are not key-value pairs
Always unique elements
LinkedList
TreeMap
HashSet
HashMap
What does it mean for a list to be "dynamic" in ArrayList?
You can easily add and remove elements
It may contain multiple types of values
It has a set size once it has been created
You can access it from anywhere in the program
Collection Framework Comes under which package?
java.lang
java.io
java.util
java.applet
Which option is correct in the following collection interface hierarchy?
List,Set,Queue
List,Set,Map
List,Map
Map,Queue,Sey
Which of the following statement about Set is true?
A HashSet cannot have a null value.
Set allows duplicate values.
Set allows null values but only single occurrence.
Set extends the Java.util.collection interface.
