logo Practice-It logo

sockPairs

Language/Type: Java Guava Multiset collections
Author: Marty Stepp (on 2013/01/22)

A common complaint is that people can't find one of the two socks in a matching pair after they do the laundry. So in this problem you'll write a method named sockPairs that looks at a collection of socks in the laundry and determines whether all types of socks occur exactly twice. Your method accepts an array of strings as a parameter; each string represents a type of sock. Your method should examine the list and return true if every unique string in the list occurs exactly 2 times, or false if any string does not occur exactly 2 times. An empty array should also cause your method to return true. For example, if passed the array [green, white, green, polkadot, red, black, red, white, black, polkadot], your method should return true because every string occurs exactly twice. If passed [green, white, green, green, white, green, red], your method should return false because "green" occurs 4 times and "red" occurs only once.

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.