Font size
Worksheetscollection
Total questions: 64
Worksheet time: 43mins
-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
-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]
Which of the following is/are correct statements?
HashSet class implements the Set interface
HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.
HashSet permits to have a single null value.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap and HashSet are threadsafe
Which of the following statement(s) is/are TRUE?
Both HashMap and HashSet are not synchronized.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap permits single null key and any number of null values.
Both HashMap and HashSet are synchronized.
{"Computer", "Programming","Networks","null"}
{"Computer", "Programming","Networks",null,"null"}
Line 11 : Genetates NullPointer Exception
Line12: Generates NullPointerException
Which of the following statement(s) is/are FALSE?
TreeSet does not preserve the insertion order of elements but elements are sorted by keys.
Objects in a TreeSet are stored in a sorted and ascending order.
TreeSet does not allow to insert Heterogeneous objects. It will throw classCastException at Runtime if trying to add hetrogeneous objects.
Comparator is note provided for TreeSet.
Which of the following is/are FALSE about HashMap in java?
It provides the basic implementation of Map interface of Java.
HashMap doesn’t allow duplicate keys but allows duplicate values.
HashMap allows null key also but only once and multiple null values.
Unsynchronized.
Synchronized
Which of the following is/ are True ?
Set is a group of ordered objects without duplicates
Map is essentially a set of (key,value) pairs with unique keys, supporting a lookup operation to find the value associated with a given key
List is a sequence of objects, with a distinguished first object, and in which each object has a unique successor.
Bag is a group of unordered objects allowing duplicates
Which statement(s) are false about maps in java?
A Map cannot contain duplicate keys and each key can map to at most one value.
A Map is an object that maps keys to values, or is a collection of attribute-value pairs.
A Map cannot contain duplicate keys and each key can map to at more than one value.
A Map is an object that maps functions to values, or is a collection of attribute-value pairs.
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
Which of the following statement is not True about Generics in java?
Generics are features of the Java programming language that allow programmers to write parameterized code.
With generics, the compiler can not detect violations at compile time, thus eliminating potential bugs.
Due to the demand of safer code, generics were added to the Java programming language.
generics allow you to write generic code
Stronger type checks at compile time
When do we use sets in java program?
To allow null and duplicate elements
You want to store elements distinctly without duplication, or unique elements.
to allow t contain duplicate keys and each key can map to at most one value
To perform lookups by keys
What will happen if an element already present in the Set is added again?
Run time error will be generated
No error, the element will be added once again to the set
Compile time error
A boolean value of false will be returned, and the value will not be added to the Set
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 exceptions is thrown by remover() method?
IOException
SystemException
ObjectNotFoundExeception
IllegalStateException
Which of these methods deletes all the elements from invoking collection?
clear();
reset();
delete();
remove();
Which of these interface declares core method that all collections will have?
Collection
EventListner
Comparator
Set
List
Which of these is an incorrect form of using method max() to obtain maximum element?
max(Collection c)
max(Collection c, Comparator comp)
max(Comparator comp)
max(List c)
Which of these methods can convert an object into a List?
SetList()
ConvertList()
CopyList()
singletonList()
Which of these is true about unmodifiableCollection() method?
unmodifiableCollection() returns a collection that cannot be modified.
unmodifiableCollection() method is available only for List and Set.
unmodifiableCollection() is defined in Collection class.
None of the mentioned.
Which of these is static variable defined in Collections?
EMPTY_SET
EMPTY_LIST
EMPTY_MAP
All of the mentioned
What implementation of Iterator can traverse a collection in both directions?
Iterator
ListIterator
SetIterator
MapIterator
Which is faster and uses less memory?
ListEnumeration
Iterator
Enumeration
ListIterator
What will be output of given code
a followed by concurrentModification Exception
a b c
a b
a c
Which interface does java.util.Hashtable implement?
Java.util.Map
Java.util.List
Java.util.HashTable
Java.util.Collection
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?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
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?
java.util.Map
java.util.Set
java.util.List
java.util.Collection
Which collection class allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized?
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
The default capacity of a Vector is:
10
12
8
0
The Comparable interface contains which called?
toCompare
compare
compareTo
compareWith
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);
}
Nullpointer exception
compiler error
2
Null value
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=audi
a=audi
a=ferrari
a=ferrari
Run time Error
Deque and Queue are derived from
Abstract class
Collection
Abstactcollection
List
What will be output of given code
1 2 3
1 followed by exception
Compile time error
run time error
Which is best suited to a multi-threaded environment?
WeakHashMap
Hashtable
HashMap
ConcurrentHashMap
TreeMap implements?
Dictionary
HashMap
AbstractMap
NavigableMap
Which of these is synchronized?
TreeMap
HashMap
Hashtable
All of the above
TreeMap
doesn't allow null key
allow many null values
Both
allow many null key
How can you sort given HashMap on basis of values
Implement Comparator interface and override its compare method
It is not possible
Implement Comparator interface and override its compareTo method
Implement Comparator interface and override its comparable method
What does Collections.sort internally uses when number of elements are less than 7?
Insertion sort
Merge sort
Quick sort
None
What does Collections.sort internally uses when number of elements are greater than 7?
Insertion sort
Merge sort
Quick sort
None
Contains no duplicate elements
Elements are not key-value pairs
Always unique elements
LinkedList
TreeMap
HashSet
HashMap
Which of the following is/are NOT correct statements?
HashSet class implements the Set interface
HashSet permits to have a single null value.
HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.
HashMap does not allow duplicate keys however it allows to have duplicate values.
HashMap and HashSet are threadsafe
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
How do you get the number of elements in an ArrayList called "list" in Java?
list.size();
list.length();
list.count();
list.getSize();
The _________ method will return the total elements in an ArrayList.
total()
size()
length()
length
Which statement below is the correct way to retrieve the first element in the nums ArrayList?
nums.get(0)
nums(0)
nums[0]
nums[1]
Given the nums ArrayList with the values [5, 4, 3, 2], what statement below removes the value 3 from the list?
nums.remove(2)
nums.remove(3)
nums.get(2) = null
nums.remove(1)
What will print when the following code executes?
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(7);
list.add(8);
list.add(9);
System.out.println(list.remove(0));
7
9
0
8
Which statement is the correct declaration and initialization of an ArrayList of String values?
ArrayList<String> name;
name = new ArrayList<String>();
ArrayList<String> name;
name = ArrayList<String>();
ArrayList name;
name = new ArrayList<String>();
String<ArrayList> name;
name = new String<ArrayList>();
public static void main (String[] args) {
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (arr1 == arr2)
System.out.println("Same");
else
System.out.println("Not same");
}}
same
not same
error
public static void main (String[] args)
{
int arr1[] = {1, 2, 3};
int arr2[] = {1, 2, 3};
if (Arrays.equals(arr1, arr2))
System.out.println("Same");
else
System.out.println("Not same");
}
}
Same
Not Same
Error
What is the length of the following array: byte[] data = { 12, 34, 9, 0, -62, 88 };
5
6
4
7
_________________ is a collection of elements used to store the same type of data.
Array
ArrayList
Case
Loop
