我用谷歌搜索过,但没有转换HashMap<String, ArrayList<Class>>
为ArrayList<Class>
. 有人可以帮我吗?
基本上,我想将下面的方法 getStudentLst 从调用构造函数中更改,并将哈希映射转换为 arrayList,如下所示。我已经尝试了很多次,但它一直在产生错误。我哪里出错了?
ArrayList<Student> arrStudLst = new ArrayList<Student>(hmpStudent.keySet());
Collectoins.sort(arrStudLst, new Comparator());
return arrStudLst;
但它不起作用并生成错误“构造函数 ArrayList(Set) 未定义
非常感谢任何帮助!亚当
/* 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;
}