Java Collection (GATE - CS)
Covers Java Collections framework including interfaces (List, Queue, Collection) and implementations (HashSet, LinkedHashSet, TreeSet, Vector)
Questions
Which of the following methods are present in List Interface?
- SubList (int startindex, int endindex)
- PreviousIndex()
- NextIndex()
- HasPrevious()
- HasMiddle()
Which of following methods are present in the Collection Interface in Java?
- HashCode()
- HasNext()
- Next()
- AllRetain()
- EnsureCapacity()
How many constructors are there for LinkedHashSet?
- 6
- 5
- 4
- 3
- 2
What is the default value for initial capacity and load factor for HashSet?
- Initial capacity: 12load factor : 0.75
- Initial capacity: 14load factor : 0.75
- Initial capacity: 16load factor : 0.75
- Initial capacity: 16load factor : 0.65
- Initial capacity: 12load factor : 0.65
Which of the following methods are present in the vector class in java?
- TrimToSize()
- SetElement(index,Element)
- Seach()
- Empty()
- Remove()
Which of the following statements are true for the methods in the queue in java collections?
- Element() method retrieves and removes the head of the queue and returns null if the queue is empty.
- Element() method retrieves but doesn’t remove the head of the queue and returns null if the queue is empty.
- Element() method retrieves and removes the head of the queue and throws exception if the queue is empty.
- Element() method retrieves but doesn’t remove the head of the queue and throw exception if the queue is empty.
- Element() method removes the head of the queue and throws exception if the queue is empty.
Which of the following statements is correct for the methods of queue in Java Collections?
- Poll() method retrieves and removes the head of the queue or returns null if the queue is empty.
- Remove() method retrieves and removes the head of the queue or returns null if the queue is empty
- Poll() method retrieves and removes the head of the queue or throws an exception if the queue is empty.
- Remove() method retrieves and removes the head of the queue, but doesn’t return anything if the queue is empty.
- Poll() method retrieves the head of the queue or returns null if the queue is empty.
Which of the following statements is correct for methods in the queue?
- Peek() method retrieves and removes the head of the queue and returns null if the queue is empty.
- Peek() method retrieves and removes the head of the queue and returns nothing if the queue is empty.
- Peek() method retrieves but doesn’t remove the head of the queue and returns null if the queue is empty.
- Peek() method retrieves and removes the head of the queue and throws exception if the queue is empty.
- Peek() method retrieves but doesn’t remove the head of the queue and throws exception if the queue is empty.
How many constructors are there of HashSet?
- 6
- 5
- 4
- 3
- 2
Which of the following methods is not present in the List Interface?
- IndexOf(Element : e)
- Set(index,element)
- Get(index)
- Remove(index)
- None of these
Which of the following methods is not present in the java collection interface?
- RetainAll(collection c)
- ToArray()
- ContainsAll()
- AddAll(Collection c)
- First()
How many constructors are there in TreeSet?
- 6
- 5
- 4
- 3
- 2