package com.mbit.test1;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class TestReturnArray {
public static void main(String[] args) {
ArrayList<Teacher> list = (ArrayList<Teacher>) returnList();
Teacher[] arrTec = new Teacher[list.size()];
arrTec = list.toArray(arrTec);
System.out.println(Arrays.toString(arrTec));
System.out.println(list.getClass());
}
public static List<Teacher> returnList(){
Teacher t1 = new Teacher("1","name","ava");
ArrayList<Teacher> a1 = new ArrayList<>();
a1.add(t1);
return a1;
}
}
class Teacher{
private String name;
private String age;
private String classroom;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getClassroom() {
return classroom;
}
public void setClassroom(String classroom) {
this.classroom = classroom;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + ", classroom=" + classroom + "]";
}
public Teacher(String name, String age, String classroom) {
super();
this.name = name;
this.age = age;
this.classroom = classroom;
}
public Teacher() {
super();
}
}
list集合转对应类型的对象数组
最新推荐文章于 2024-06-28 13:12:37 发布