Java Collections Framework
Questions covering the Java Collections Framework including interfaces like Collection, List, Queue, Set, and implementations like HashSet, LinkedHashSet, TreeSet, and Vector
Questions
Which of following methods is present in the Collection interface in Java?
- hashCode()
- hashNext()
- Next()
- AllRetain()
- ensureCapacity()
How many constructors are there for LinkedHashSet?
- 6
- 5
- 4
- 3
- 2
What are the default values for initial capacity and load factor for HashSet?
- Initial capacity : 12
Load factor : 0.75 - Initial capacity : 14
Load factor : 0.75 - Initial capacity : 16
Load factor : 0.75 - Initial capacity : 16
Load factor : 0.65 - Initial capacity : 12
Load factor : 0.65
Which of the following methods is present in List interface?
- subList(int startindex, int endindex)
- previousIndex()
- nextIndex()
- hasPrevious()
- hasMiddle()
Which of the following methods is present in the vector class in Java?
- trimToSize()
- setElement(index,Element)
- Seach()
- Empty()
- Remove()
Which of the following statements is true for methods in 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 throws 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 in 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 an exception if the queue is empty.
- Peek() method retrieves, but doesn’t remove the head of the queue and throws an exception if the queue is empty.
How many constructors are there of TreeSet class?
- 6
- 5
- 4
- 3
- 2
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)
- Setthere(index,element)
- Get(index)
- Remove(index)
- Merge(c:collection,c1:collection)
Which of the following methods is not present in the Java Collections interface?
- retainAll(collection c)
- toArray()
- containsAll()
- addAll(Collection c)
- First()