Problem: Write a method called personIndex() where you pass in an ArrayList of person objects. Place each person object with its corresponding id number in HashMap. Return a collection of the person objects in order.
Could someone explain / show how I would do this?
This is my code:
public Collection<person> personIndex(ArrayList<Person> parameterArr)
{
HashMap<String, Person> answerMap = new HashMap<String, Person>();
for (Person p: parameterArr)
{
answerMap.put(p.getID(), p)
}
return answerMap.values();
}
Question: Is my code correct? Will it return a collection?
I want to know if this is a syntactically correct way to return a collection, and also how would you write this method?
PROBLEM:
when you write the method nothing is being returned but the compiler says everything is syntactically correct
Thank you!