logo CodeStepByStep logo

counts

Language/Type: Java Collections List Set Map
Related Links:

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, 7, 29]

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

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.