1
我正在學習Java Streams並想用java 8功能替換下面的代碼。用Java流替換內部for循環
我能夠使用stream.filter()和stream.map功能,但我無法用java 8功能替換下面的代碼。
List<Subject> subjects= null;
Set<SubjectData> subjectData= new SubjectData();
for (String name: studentNames)
{
//subjects = student.getSubjects(name);
// consider instead of above line , which returns a collection of <Subject>
for (Subject subject : subjects)
{
subjectData.add(new SubjectData(subject.syllabus(), subject.code()));
}
}
任何指針將不勝感激
當然,你的意思是'new HashSet <>()'? –
'學生'從哪裏來? –
yes此代碼的輸出應爲所有學生返回的集合(存在於外循環中) –
Mahiz