020-005-010
Using Collections Utility Methods
Medium
Problem Description
Using Collections Utility Methods
In this problem: You will create a program that uses the collection framework's Collections utility class methods including sort(), reverse(), frequency(), max(), and min() to manipulate an ArrayList and display the results to standard output.
Learning Objective: Understand how to use the key utility methods of java.util.Collections class for sorting, searching, and statistical operations on lists
Overview
Store data in an ArrayList<Integer> and display the results of various Collections class operations.
Specifications
- Add the following values to
ArrayList<Integer>in order: 5, 3, 8, 1, 3, 9, 2 - Display the list immediately after adding
- Sort ascending with
Collections.sort()and display - Reverse with
Collections.reverse()and display - Display the frequency of value 3 using
Collections.frequency() - Display the maximum value using
Collections.max() - Display the minimum value using
Collections.min()
Output Format
Original: [5, 3, 8, 1, 3, 9, 2]
Sorted: [1, 2, 3, 3, 5, 8, 9]
Reversed: [9, 8, 5, 3, 3, 2, 1]
Frequency of 3: 2
Max: 9
Min: 1
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up