I am working with java-8. Please 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 perform 2 check -
s.getDepartment() != null ; // 1st check
and
s.getDepartment().getCode().equals("CS") // 2nd check
Is there any way that I can store the value of s.getDepartment() to some variable (say dept) so that in second check I can write -
dept.getCode().equals("CS");