I realize that variations of this question have been asked before, but I am having a uniquely difficult time figuring out how to complete the following task:
I have an object that looks something like this (please note, "Skill" and "Certification" are ENUMS):
Public Employee {
String name;
List<Skill> employableSkills = new ArrayList<>();
List<Certification> certifications = new ArrayList<>();
...
}
In another class, I've got a
List<Employee> listOfEmployees;
and I'm trying to loop through it like this:
// determine the total number of employees who know Java
int numberOfEmployeesWhoKnowJava = 0;
for (Employee employee : listOfEmployees) {
if (employee.employableSkills.contains( ?? )) {
numberOfEmployeesWhoKnowJava++;
}
I'm struggling to get the exact syntax on the if-statement. I have tried this:
if(employee.employableSkills.contains(Employee.EmployableSkills.JAVA)) {
but EmployableSkills in this string gets "cannot resolve symbol."
How should I loop through the List on each Employee object and check if it contains JAVA?
Edit: It turns out I was making a fundamental error. In OOP, it is best not to expose the data from one class to another class. Instead, I wrote getters in the Employee class, then called those getters from my other class. That way, the data in Employee is not directly exposed to the class that needed it.