This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class School { | |
private final String _name; | |
private final Stream<Student> _students; | |
public School(String schoolName, Stream<Student> students){ | |
_name = schoolName; | |
_students = students; | |
} | |
public String get_name() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C# | |
IEnumerable<string> schoolNames = schools.Select(s => s.get_name()); | |
// Java | |
Stream<String> schoolNames = schools.map(s -> s.get_name()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
IEnumerable<Student> studentsInAllSchools = schools.SelectMany(s => s.get_students()); | |
// java | |
Stream<Student> studentsInAllSchools = schools.flatMap(s -> s.get_students()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
List<Student> studentsInAllSchools = studentsInAllSchools.ToList(); | |
// java | |
List<Student> studentsInAllSchoolsList = studentsInAllSchools.collect(Collectors.toList()); | |
// or, if you specifically want an arrayList.. | |
List<Student> studentsInAllSchoolsArrayList = studentsInAllSchools.collect(Collectors.toCollection(ArrayList::new)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
bool doesThisStudentExist = studentsInAllSchools.Any(s => s.get_name() == "Alex"); | |
// java | |
boolean doesThisStudentExist = studentsInAllSchools.anyMatch(s -> s.get_name() == "Alex"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
bool doAllStudentsExceed100cmInHeight = studentsInAllSchools.All(s => s.get_height() > 100); | |
// java | |
boolean doAllStudentsExceed100cmInHeight = studentsInAllSchools.allMatch(s -> s.get_height() > 100); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
IEnumerable<Student> studentsInFirstYear = studentsInAllSchools.Where(s => s.get_year() == 1); | |
// java | |
Stream<Student> studentsInFirstYear = studentsInAllSchools.filter(s -> s.get_year() == 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
IEnumerable<IGrouping<int, IEnumerable<Student>>> studentsGrouppedByYear = studentsInAllSchools.GroupBy(s => s.get_year()); | |
// java | |
Map<Integer, List<Student>> studentsGrouppedByYear = studentsInAllSchools.collect(Collectors.groupingBy(s -> s.get_year())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
schools.ForEach(s => s.set_address("test address")); | |
// java | |
schools.forEach(s -> s.set_address("test address")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// c# | |
int count = schools.count(); | |
double average = allHeights.average() | |
// java | |
int count = schools.count(); | |
OptionalDouble average = allHeights.average(); |
OlderNewer