Declaration:
void printNames(Iterable<Teacher> teachers) {
for (Teacher teacher : teachers) {
System.out.printf("%s ", teacher.getName());
}
}
Usage:
switch (selection) {
case 1:
printNames(teachers);
break;
solved Creating a method in Java