I work with java-8. See the following code snippet -
studentsOfThisDept = students.stream()
.filter(s -> (student != null
&& s.getDepartment() != null
&& s.getDepartment().getCode().equals("CS")
))
.collect(Collectors.toList());
Here I have to do 2 check -
s.getDepartment() != null ;
and
s.getDepartment().getCode().equals("CS")
Is there a way to save the value s.getDepartment()for some variable (e.g. dept) so that in the second check I could write -
dept.getCode().equals("CS");
source
share