This is a somewhat academic question about java efficiency wrt collections. Assume there are two classes SearchForm and Manager. SearchForm has a Collection of Persons and calls Manager to find out if a Person has a subscription, it will then iterate over persons to find their subscription status. Object Person has an int id (Person.getId()). Which is more energy-efficient in Java:
Map<Integer, Boolean> MapPersonSubscription(Collection<Person> persons, Date date, int subscriptionId);
Map<Person, Boolean> MapPersonSubscription(Collection<Person> persons, Date date, int subscriptionId);
The collection of Persons is already in memory, does it cost extra (in some way) to use its elements as Map keys in the returned map? Is it 'cheaper' to return a map using the smaller key (int) but perform Person.getId in the calling class when retrieving each persons value from the map?
This is an toy example, assume Manager needs Person, not just Person.getId to find the subscription and it is preferable to query a subsciption for all persons at once because of the underlying db query.
Related question: Most efficient key object type in a hash map?