Which of the following reflects a valid definition (signature and behavior) for the copyFromArrayListToHashMap
ArrayList<Student> students=fp.readNamesAndCreateObjects("D:\\AAUJ\\AAA\\StudentNames.txt", "student");
HashMap<Integer, Student> studentsHashMap=fp.copyFromArrayListToHashMap(students);
for(HashMap.Entry<Integer,Student> entries :studentsHashMap.entrySet())
{
System.out.println("Key = " + entries.getKey() + " , Value = " + entries.getValue());
}
Which of the following reflects a valid definition (signature and behavior) for the copyFromArrayListToHashMap
default Student copyFromArrayListToHashMap(ArrayList<E> objects)
{
HashMap<Integer,E> result=new HashMap<>();
for(int i=0;i<objects.size();i++)
{
result.put(i, objects.get(i));
}
return result;
}
default HashMap<T,E> copyFromArrayListToHashMap(ArrayList<E> objects)
{
HashMap<Integer,E> result=new HashMap<>();
for(int i=0;i<objects.size();i++)
{
result.put(i, objects.get(i));
}
return result;
}
default HashMap<Integer,E> copyFromArrayListToHashMap(ArrayList<E> objects)
{
HashMap<Integer,E> result=new HashMap<>();
for(int i=0;i<objects.size();i++)
{
result.put(i, objects.get(i));
}
return result;
}
default HashMap<T,E> copyFromArrayListToHashMap(ArrayList<T> objects)
{
HashMap<Integer,E> result=new HashMap<>();
for(int i=0;i<objects.size();i++)
{
result.put(i, objects.get(i));
}
return result;
}
Step by step
Solved in 2 steps