I have a simple example below
static class Town {
School school;
}
static class School {
List<Subject> subjects;
}
static class Subject{
String name;
}
I would like to implement a method that returns Names of the subjects for a given Town, the town can be null as well
List<String> getSubjectNames(Town town) {
return Optional.ofNullable(town)
.map(town1 -> town1.school)
.map(school -> school.subjects.stream())
.flatMap(subjects -> )
...
}
How do you correctly convert subjectstream to subject for map operations. Any pointers would be appreciated.