0

MAP Java (GATE - CS)

Description: Concept Based Questions
Number of Questions: 15
Created by:
Tags: Concept Based Questions Java Basics
Attempted 0/15 Correct 0 Score 0

Which of the following methods cannot be invoked with the object of TreeMap constructor?

  1. descendingMap()

  2. firstEntry()

  3. floorEntry(K key)

  4. headMap(K toKey)

  5. fixedMap()


Correct Option: E
Explanation:

This is the correct answer. There is no method named FixedMap() in TreeMap class. So, this method cannot be invoked from Object of TreeMap class. So, this answer is correct.

Which of the following methods is present in Map interface in Java collections framework?

  1. containsKey(object)

  2. containValue(object)

  3. getKey(object)

  4. keysSet(object)

  5. removeKey(object)


Correct Option: A
Explanation:

This is the correct answer. containsKey(object) method is present in the Map interface in Java collections framework. This method returns true if this Map contains a mapping for a specified key. So, this is the correct answer.

How many constructors of HashMap class are there in Java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: D
Explanation:

This is the correct choice because there are 3 constructors of HashMap class. These are:   HashMap(): creates a Map with default initial capacity and load factor HashMap(int initialCap, float load): creates a Map with default specified initial capacity and load factor HashMap(m : Map): creates a Map with existing Map

Which of the following methods is not present in Map interface?

  1. putAll(map : m)

  2. Get(key : K)

  3. isEmpty()

  4. removeLast()

  5. put(Key : K, Value : V)


Correct Option: D
Explanation:

This is the correct choice because removeLast() method is not present in the Map interface. It is present in LinkedList class. This method removes the last element from the list.

Which of the following methods cannot be invoked with the object of ConcurrentHashMap class?

  1. putIfAbsent(K key, V value)

  2. replace(K key, V oldValue, V newValue)

  3. replace(K key, V value)

  4. containsValue(Object value)

  5. None of these


Correct Option: E
Explanation:

As explained, all the given methods can be invoked from the object of ConcurrentHashMap class. So, this is the correct choice.

Which of the following methods is/are present in the PriorityQueue class in Java?

  1. poll()

  2. offer(E e)

  3. contains(object : o)

  4. Both (1) and (2)

  5. All of the above


Correct Option: E
Explanation:

As explained, all the methods are present in the PriorityQueue class. So, this answer is correct.

How many constructors of HashTable class are there in Java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is the correct choice because there are 4 constructors of HashTable class in Java collections framework. These constructors are: 1) Hashtable(): constructs a new, empty hashtable with a default initial capacity (11) and load factor (0.75) 2) Hashtable(int initialCapacity): constructs a new, empty hashtable with the specified initial capacity and default load factor (0.75) 3) Hashtable(int initialCapacity, float loadFactor): constructs a new, empty hashtable with the specified initial capacity and the specified load factor 4) Hashtable(Map t): constructs a new hashtable with the same mappings as the given map

Which of the following methods is not present in the Map interface in Java collections framework?

  1. containsKey(object)

  2. containsValue(object)

  3. Get(key : K)

  4. Put(key : K, Value : V)

  5. setValue(Value : V)


Correct Option: E
Explanation:

This is the correct choice because setValue(Value : V) method is not present in the Map interface. This method is present in the Entry interface. This method replaces the value in this entry with a new specified value.

How many constructors of TreeMap are there in Java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: C
Explanation:

This is the correct answer. There are four constructors of TreeMap. These are:

TreeMap(): It creates an empty Map. TreeMap(Comparator comp): The second form constructs an empty tree-based map that will be sorted by using the Comparator comp. TreeMap(Map m): The third form initialises a tree map with the entries from m, which will be sorted by using the natural order of the keys. TreeMap(SortedMap sm): The fourth form initialises a tree map with the entries from sm, which will be sorted in the same order as sm.

Which of the following methods can be invoked from the object of TreeMap constructor?

  1. higherEntry(K key)

  2. pollLastEntry()

  3. descendingKeySet()

  4. Both (1) and (3)

  5. All of the above


Correct Option: E
Explanation:

As explained, all the methods can be invoked from the TreeMap object. So, this answer is correct.

Which of the following methods is not present in the Collection interface?

  1. retainAll(Collection c)

  2. containsAll(Collection c)

  3. toArray(T[] a)

  4. firstEntry()

  5. equals(Object o)


Correct Option: D
Explanation:

This is the correct choice because firstEntry() method is not present in the Collection interface. It is used for Map interface and its classes. This method returns a key-value mapping associated with the least key in this map or null if the map is empty. So, this is the correct choice.

How many constructors of ConcurrentHashMap class are there in Java collections framework?

  1. 8

  2. 7

  3. 6

  4. 5

  5. 4


Correct Option: D
Explanation:

This is the correct choice because there are 5 constructors of ConcurrentHashMap class. These are:

1) ConcurrentHashMap(): creates a new, empty map with a default initial capacity (16), load factor (0.75) and concurrencyLevel (16) 2) ConcurrentHashMap(int initialCapacity): creates a new, empty map with specified initial capacity and with default load factor (0.75) and concurrencyLevel (16) 3) ConcurrentHashMap(int initialCapacity, float loadFactor): creates a new, empty map with specified initial capacity and load factor, and with the default concurrencyLevel (16) 4) ConcurrentHashMap(int initialCapacity, float loadFactor, int concurrencyLevel): creates a new, empty map with specified initial capacity, load factor and concurrencyLevel 5) ConcurrentHashMap(Map m): creates a new map with the same mappings as the given map

Which of the following methods is present in the Vector class?

  1. copyInto(array : Object[])

  2. removeFirst()

  3. lastIndexOf(element : e)

  4. addLast(object)

  5. Set(int index, element e)


Correct Option: A
Explanation:

This is the correct answer. copyInto(array : Object[]) method is present in the Vector class and it copies the elements in this vector to an array. 

How many constructors of LinkedHashMap class are there in Java collections framework?

  1. 6

  2. 5

  3. 4

  4. 3

  5. 2


Correct Option: D
Explanation:

This is the correct choice because there are 3 constructors of LinkedHashMap class. These are:LinkedHashMap(): creates a default Map with default initial capacity and loadfactor LinkedHashMap(Map : m): creates a map with the existing map m LinkedHashMap(int capacity, float loadfactor, Boolean accessorder): creates a map with specified initial capacity, load factor and access order of elements

Which of the following methods is present in Map interface in Java collections framework?

  1. getKey()

  2. getValue()

  3. setValue(Value : V)

  4. keyset()

  5. getKeys()


Correct Option: D
Explanation:

This is the correct choice. Keyset() method is present in the Map interface and it returns a set consisting of the keys in this map. 

- Hide questions