Java Collection (GATE - CS)

Covers Java Collections framework including interfaces (List, Queue, Collection) and implementations (HashSet, LinkedHashSet, TreeSet, Vector)

12 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following methods are present in List Interface?

  1. SubList (int startindex, int endindex)
  2. PreviousIndex()
  3. NextIndex()
  4. HasPrevious()
  5. HasMiddle()
Question 2 Multiple Choice (Single Answer)

Which of following methods are present in the Collection Interface in Java?

  1. HashCode()
  2. HasNext()
  3. Next()
  4. AllRetain()
  5. EnsureCapacity()
Question 3 Multiple Choice (Single Answer)

How many constructors are there for LinkedHashSet?

  1. 6
  2. 5
  3. 4
  4. 3
  5. 2
Question 4 Multiple Choice (Single Answer)

What is the default value for initial capacity and load factor for HashSet?

  1. Initial capacity: 12load factor : 0.75
  2. Initial capacity: 14load factor : 0.75
  3. Initial capacity: 16load factor : 0.75
  4. Initial capacity: 16load factor : 0.65
  5. Initial capacity: 12load factor : 0.65
Question 5 Multiple Choice (Single Answer)

Which of the following methods are present in the vector class in java?

  1. TrimToSize()
  2. SetElement(index,Element)
  3. Seach()
  4. Empty()
  5. Remove()
Question 6 Multiple Choice (Single Answer)

Which of the following statements are true for the methods in the queue in java collections?

  1. Element() method retrieves and removes the head of the queue and returns null if the queue is empty.
  2. Element() method retrieves but doesn’t remove the head of the queue and returns null if the queue is empty.
  3. Element() method retrieves and removes the head of the queue and throws exception if the queue is empty.
  4. Element() method retrieves but doesn’t remove the head of the queue and throw exception if the queue is empty.
  5. Element() method removes the head of the queue and throws exception if the queue is empty.
Question 7 Multiple Choice (Single Answer)

Which of the following statements is correct for the methods of queue in Java Collections?

  1. Poll() method retrieves and removes the head of the queue or returns null if the queue is empty.
  2. Remove() method retrieves and removes the head of the queue or returns null if the queue is empty
  3. Poll() method retrieves and removes the head of the queue or throws an exception if the queue is empty.
  4. Remove() method retrieves and removes the head of the queue, but doesn’t return anything if the queue is empty.
  5. Poll() method retrieves the head of the queue or returns null if the queue is empty.
Question 8 Multiple Choice (Single Answer)

Which of the following statements is correct for methods in the queue?

  1. Peek() method retrieves and removes the head of the queue and returns null if the queue is empty.
  2. Peek() method retrieves and removes the head of the queue and returns nothing if the queue is empty.
  3. Peek() method retrieves but doesn’t remove the head of the queue and returns null if the queue is empty.
  4. Peek() method retrieves and removes the head of the queue and throws exception if the queue is empty.
  5. Peek() method retrieves but doesn’t remove the head of the queue and throws exception if the queue is empty.
Question 9 Multiple Choice (Single Answer)

How many constructors are there of HashSet?

  1. 6
  2. 5
  3. 4
  4. 3
  5. 2
Question 10 Multiple Choice (Single Answer)

Which of the following methods is not present in the List Interface?

  1. IndexOf(Element : e)
  2. Set(index,element)
  3. Get(index)
  4. Remove(index)
  5. None of these
Question 11 Multiple Choice (Single Answer)

Which of the following methods is not present in the java collection interface?

  1. RetainAll(collection c)
  2. ToArray()
  3. ContainsAll()
  4. AddAll(Collection c)
  5. First()
Question 12 Multiple Choice (Single Answer)

How many constructors are there in TreeSet?

  1. 6
  2. 5
  3. 4
  4. 3
  5. 2