怎么把对象数组转换为集合
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么把对象数组转换为集合相关的知识,希望对你有一定的参考价值。
Student s1=new Student("张三","20");
Student s2=new Student("李四","21");
Student s3=new Student("王五","22");
Student s4=new Student("赵六","23");
Student s5=new Student("马奇","24");
Student [] demo=s1,s2,s3,s4,s5;
List al=new ArrayList();
al=(ArrayList) Arrays.asList(demo);
request.setAttribute("al", al);
这样转报错了 java.lang.ClassCastException: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
Student s2=new Student("李四","21");
Student s3=new Student("王五","22");
Student s4=new Student("赵六","23");
Student s5=new Student("马奇","24");
Student [] demo=s1,s2,s3,s4,s5;
List<Student> al=new ArrayList<Demo>();
for(int i=0;i<demo.length;i++)
list.add(demo[i]);
本回答被提问者和网友采纳 参考技术B 我估计
al=(ArrayList) Arrays.asList(demo);
(ArrayList)改成(list)试试
以上是关于怎么把对象数组转换为集合的主要内容,如果未能解决你的问题,请参考以下文章