gpt4 book ai didi

java - 如何在不同的类中获取2个ArrayList?

转载 作者:行者123 更新时间:2023-12-01 12:33:15 26 4
gpt4 key购买 nike

我有两个类StudentWorker。我定义了两个 ArrayList 并为每个类都有一个 getter。

Worker 类:

private List<Worker> WorkerList = new ArrayList<Worker>();

public List<Worker> getWorkerList() {
return WorkerList;
}

public Worker(String first, String last, float WeekSalary,
float WorkingHours) {
super(first, last);
this.setWeekSalary(WeekSalary);
this.setWorkingHoursPerDay(WorkingHours);
// TODO Auto-generated constructor stub
}

学生类(class):

private List<Student> StudentList = new ArrayList<Student>();

public Student(String first, String last, int gradeValue) {
super(first, last);
this.setGrade(gradeValue);
}

public List<Student> getStudentList() {
return StudentList;
}

这里的问题是如何从另一个类获取这两个ArrayList?例如MergeClass

最佳答案

只需调用MergeClass中的getter方法即可。你可以有这样的东西:

Worker w = new Worker();
Student s = new Student();
List<Worker> workerList = w.getWorkerList();
List<Student> studList = s.getStudentList();

关于java - 如何在不同的类中获取2个ArrayList?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25778687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com