I have googled but did not come accross converting HashMap<String, ArrayList<Class>> to ArrayList<Class>. Could someone help me please?
Basically, i want to change my method getStudentLst below from calling constructor and convert hash map to arrayList as below. I have tried many times but it keeps generating error.Where i am going wrong?
ArrayList<Student> arrStudLst = new ArrayList<Student>(hmpStudent.keySet());
Collectoins.sort(arrStudLst, new Comparator());
return arrStudLst;
but it did not work and generate error "The constructor ArrayList(Set) is undefined
any help much appreciated! adan
/* works well but i want to avoid calling constructor */
public ArrayList<Student> getStudentLst(HashMap<String, ArrayList<Student>> hmpStudent)
{
ArrayList<Student> arrStudLst = new ArrayList<Student>();
Set<String> keylst = hmpStudent.keySet();
Student student;
for(String keys: keylst)
{
for(Student f: hmpStudent.get(keys))
{
student = new Student(f.getName(),f.getGrade(), f.getTeacher()); arrStudLst.add(student);
}
}
Collections.sort(arrStudLst,new StudentComparator());
return arrStudLst;
}