[Solved] Java – Getting Difference Between Two Lists [closed]


For example, to see who is just a coach and not also a teacher without losing your list of coaches:

List<String> coaches = new ArrayList<>();
coaches.add("Josh");
coaches.add("Jake");
coaches.add("Tyler");

List<String> teachers = new ArrayList<>();
teachers.add("Josh");
teachers.add("Jake");

List<String> CoachesNotAlsoTeachers = new ArrayList<>();
CoachesNotAlsoTeachers.add(coaches);
CoachesNotAlsoTeachers.removeAll(teachers);

for (String name : CoachesNotAlsoTeachers ) {
    System.out.println("Name is: " + name);
}

2

solved Java – Getting Difference Between Two Lists [closed]