logo Practice-It logo


Language/Type: Java Collections Sets and Maps
Author: Marty Stepp

Write a method counts that accepts a List of integers and a Set of integers as parameters, and returns a map from each value in the set to the number of occurrences of that value in the list. For example, if your method is passed the following list and set as parameters:

  • list: [4, -2, 3, 9, 4, 17, 5, 29, 14, 87, 4, -2, 100]
  • set: [-2, 4, 29]

Then your method should return the map {-2=2, 4=3, 29=1}, because there are two occurrences of -2, three occurrences of 4, and one occurrence of 29.

Type your solution here:

This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.