Write a method commonCustomers
that accepts two parameters, a Map
from customer names (strings) to their television account numbers (integers) and a Map
from customer names (strings) to their internet account numbers (integers), and returns a Map
from customer names (strings) to their account number (integers) for each customer that has both a television account and a internet account. Assume that each customer with both types of accounts has the same account number for both accounts. For example, if a map tvAccounts
contains these pairs:
{Marty=84321, David=23435, Stef=13266, Kim=62692, Lisa=25262}
and a map internetAccounts
contains these pairs:
{Rob=93754, David=23435, Angela=42622, Kim=62692, Jason=36212}
The call of commonCustomers(tvAccounts, internetAccounts)
should return a map containing these pairs:
{David=23435, Kim=62692}
because David and Kim have both television accounts and internet accounts. You may assume that the maps passed are not null
and that no key or value in either is null
. If either of the maps are empty or contain no common customers, your method should return an empty Map
. You may create one collection of your choice as auxiliary storage to solve this problem.