176k views
1 vote
You need a collection to represent secret agents. Every agent has a unique codename that identifies them, and an Agent object that represents them. The best collection for this would be

User Gichamba
by
6.5k points

1 Answer

3 votes

Answer:

A HashMap< String, Agent >

is a best collection for this

Step-by-step explanation:

Collection is basically a framework that is used in order to perform operations on data and to store and manipulate objects.

HashMap is a Map based collection where Map is a data structure of interface which allows the key and value pairs mapping and HashMap is a collection class used to store these key-value pairs of data.

The syntax is:

HashMap<key, value>

So in HashMap< String, Agent > statement the String is used to store the codename for every agent and Agent is an object that represents each agent. So this is represented as key-value pair using HashMap.

User Cunningdave
by
6.7k points