nguyen dung
nguyen dung

Reputation: 15

How to get 2 ArrayList in different class?

I have two class Student and Worker. In that I define two ArrayList and have a getter for each class.

Worker Class:

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
}

Student 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;
}

The problem here is how can I get these two ArrayList from another class? For example a MergeClass?

Upvotes: 0

Views: 56

Answers (2)

Vitor Freitas
Vitor Freitas

Reputation: 166

public class MergeClass<T>
{
    private List<T> a;
    private List<T> b;
    public MergeClass(List<T> a, List<T> b)
    {
        this.a = a;
        this.b = b;
    }

    public void merge()
    {
       //
    }
}

From what I understand is that what you need. Hope that it can help.

Upvotes: 0

lxcky
lxcky

Reputation: 1668

Simply call the getter methods in MergeClass. You can have something like:

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

Upvotes: 1

Related Questions