Extended_Java_Collections_and_Map_Test_Paper
Extended_Java_Collections_and_Map_Test_Paper
Paper
Question 1: Basic List Operations with ArrayList
1. Write a Java program that performs the following operations on an ArrayList of integers:
- Add 10 integers (ranging from 1 to 100) to the ArrayList.
- Print the ArrayList.
- Retrieve and print the first, third, and last elements in the ArrayList.
- Remove the second element and print the updated ArrayList.
**Question:** What is the time complexity of the operations `add()`, `remove()`, and
`get()` in ArrayList? How does an ArrayList differ from other List implementations like
LinkedList?
**Question:** How does HashSet ensure uniqueness of elements? How does TreeSet
differ from HashSet in terms of ordering and performance? When would you choose one
over the other?
**Question:** How does HashMap handle case sensitivity and punctuation while
counting word frequencies? Can you modify the program to handle these issues efficiently?
**Question:** How does a TreeMap ensure its elements are sorted? What are the key
differences between HashMap and TreeMap regarding performance and sorting? When
would you prefer one over the other?
**Question:** How does LinkedHashMap maintain the order of elements? How does it
differ from HashMap, and when would you choose LinkedHashMap over HashMap?
while (iterator.hasNext()) {
}
}
**Question:** What advantages do streams offer for filtering and sorting collections?
How do streams improve code readability and performance in real-world applications?
**Question:** How does TreeMap handle sorting based on values? What challenges
might arise when sorting values in TreeMap, and how can you use a custom Comparator to
solve this?
**Question:** How do HashMap and TreeMap differ in terms of time complexity for
insertion, retrieval, and deletion operations? In what scenarios would you prefer one over
the other in terms of performance?
**Question:** How does a PriorityQueue maintain order? What is the time complexity
for insertion and removal in a PriorityQueue? When is it appropriate to use a PriorityQueue
in real-world applications?
**Question:** How can you sort and filter a collection based on multiple attributes?
How do streams handle this complexity, and what are the best practices for using streams
with complex filters and sorts?
**Question:** What are the advantages of using a Deque over a Queue or Stack? How
can a Deque improve the efficiency of operations where elements are added or removed
from both ends of a collection?