0% found this document useful (0 votes)
2 views2 pages

Practice Problem on Java Collections

The document outlines practice problems focused on Java Collections, including operations on ArrayLists, HashMaps, LinkedLists, HashSets, and Vectors. It covers tasks such as sorting custom objects, finding specific entries, and calculating averages or totals. Additionally, it includes custom sorting requirements for employees, students, and books based on various attributes.

Uploaded by

sajjad1027
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Practice Problem on Java Collections

The document outlines practice problems focused on Java Collections, including operations on ArrayLists, HashMaps, LinkedLists, HashSets, and Vectors. It covers tasks such as sorting custom objects, finding specific entries, and calculating averages or totals. Additionally, it includes custom sorting requirements for employees, students, and books based on various attributes.

Uploaded by

sajjad1027
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Practice problem on Java Collections

1. ArrayList Operations:

a. Create an ArrayList of custom objects (e.g., Person) that have attributes like
name, age, and address. Add a few persons to the list.
b. Implement a method to sort the list of persons by age in ascending order.
c. Find the person with the highest age in the list.

2. HashMap Operations:

a. Create a HashMap that maps student IDs to a list of courses they are enrolled in.
Add entries for multiple students and their courses.
b. Implement a method to find all students who are enrolled in a specific course.
c. Calculate the average number of courses per student in the map.

3. LinkedList Operations:

a. Create a doubly-linked list of custom objects (e.g., Song) that have attributes like
title, artist, and duration. Add several songs to the list.
b. Implement a method to shuffle the songs randomly in the list.
c. Calculate the total duration of all songs in the list.

4. HashSet Operations:

a. Create a HashSet of custom objects (e.g., Product) representing products.


Products have attributes like name, category, and price. Add multiple products to
the set.
b. Implement a method to find the most expensive product in the set.
c. Determine the unique categories of products in the set.

5. Sorting Employees

You have a list of employees with attributes like name, salary, and age. Write a
Comparator to sort the employees by salary in ascending order.

6. Sorting Students

You have a list of students with attributes like name, GPA, and enrollment year. Create a
Comparator to sort the students by GPA in descending order, and if two students have
the same GPA, sort them by enrollment year in ascending order.
7. Custom Sorting

You have a list of custom objects representing books. These objects have attributes like
title, author, and publication year. Create a Comparator that sorts the books by author's
last name (consider the author's name as "FirstName LastName").

8. Vector Operations:

a. Create a Vector of custom objects (e.g., Order) representing customer orders


with attributes like order ID, date, and total amount. Add multiple orders to the
vector.
b. Implement a method to filter and retrieve all orders placed within a specific date
range.
c. Calculate the total revenue generated by the orders in the vector.

You might also like