If I have an array list of Courses, each with a name and array of students, what is an easy way of merging all the courses with the same name so that one course name only appears once with an array of all the students?
So that something like this:
ArrayList<Course> courses = {Course("math", {student1, student2}),
Course("art", {student3, student4}),
Course("math", {student5, student6})};
Would turn into this:
ArrayList<Course> courses = {Course("math", {student1, student2, student5, student6}),
Course("art", {student3, student4})};
EDIT: Here are the course and student classes, but I don't think they should be too important, I just want to be able to add the arrays of students together.
public class Course {
String name;
String[] students;
public Course(String name, String[] students) {
this.name = name;
this.students = students;
}
}
public class Student {
String name;
public Student(String name) {
this.name = name;
}
}