Script Valley
Java: Complete Language Course
Java Collections Framework/Assessment

Practice & Assessment

Test your understanding of Java Collections Framework

Multiple Choice Questions

5
1

What is the time complexity of ArrayList.get(int index)?

2

What does HashMap do when you call put() with a key that already exists?

3

In a Stream pipeline, when do intermediate operations like filter() actually execute?

4

What must a class implement to use it as a HashMap key correctly?

5

What does the ? extends Number wildcard mean in a generic method parameter?

Coding Challenges

1
1

Word frequency counter using HashMap

Write a method Map<String, Integer> countWords(String text) that splits the input text on whitespace, normalizes each word to lowercase, strips punctuation using replaceAll, and counts occurrences in a HashMap. Then write a second method List<String> topN(Map<String, Integer> freq, int n) that returns the n most frequent words sorted descending by count. Test with a paragraph of at least 50 words. Input: a String of text. Output: Map of word counts and top-5 list. Time estimate: 20–25 minutes.

Medium

Mini Project

1

Student Grade Book

Build a GradeBook class that stores students and their scores. Use a Map<String, List<Integer>> where the key is the student name and the value is a list of scores. Implement: addScore(String name, int score), getAverage(String name) returning a double, getTopStudent() returning the name with the highest average, printReport() that uses Streams to compute averages and prints sorted descending by average. Add a method getAllAbove(double threshold) that returns a List of student names with average above the threshold using filter and collect. Demonstrate all methods in main with at least 5 students and varying scores.

Medium