NEW
Font size
Worksheetsjava collections
Total questions: 31
Worksheet time: 16mins
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
