Ôn tập lập trình Java (MT2 Review Solutions) - Ching and Christines
- 페이지 수
- 11
- 형식
- 크기
- 133 KB
- 언어
- EN · English
- Trường
- University of California, Berkeley
- 조회수
- 0
- 댓글
- 0
- Lượt tải
- 0
미리보기 생성 중...
Tài liệu ôn tập giữa kỳ về lập trình Java, bao gồm các bài tập thực hành về streams và iterators.
- 문서명
- Ôn tập lập trình Java (MT2 Review Solutions) - Ching and Christines
- 학교 / 강의
- University of California, Berkeley · Lập trình Java
- 내용
- Tài liệu ôn tập giữa kỳ về lập trình Java, bao gồm các bài tập thực hành về streams và iterators.
- 목차
- 이 문서는 명확한 목차가 없습니다.
- 페이지 수
- 11 페이지
- 업로더
- Uni24h
설명
Trích nội dung tài liệu
Midterm 2 Review Solutions Streams Intermediate Operations to Know 1. stream(): Converts a collection into a stream 2. sorted(Comparator c): Sorts the stream using c, which can also be a lambda 3. map(Function f)(): Applies f to each element in the stream 4. filter(Predicate p): Tests each element with p to see if it should remain in the stream Terminal Operations to Know 1. reduce(BinaryOperator accumulator): Applies the accumulator and combines the elements in the stream, two at a time. Returns an Optional. 2. collect(Collector c): Turns the stream into a collection. To a List: Collectors.toList() To a Set: Collectors.toSet() To a Map: Collectors.grooupingBy(Function f) 3. forEach(Consumer action) Practice Problems Given the following classes, write methods to perform the desired operations. You may only use one semicolon per method. public class Student { public int getLabSection() { ... } public int getAge() {...} public Group getGroup {...} } public class Group { public int size() {...} public Group merge(Group other) { ... } } 1 1. Collect all the unique lab sections from a list of students. There should not be duplicates. public Collection<Integer> uniqueSections(List<Student> lst) { return lst.stream() .map(Student::getLabSection) .collect(Collectors.toSet()); } 2. Each TA submits a list of their students. Write a method that will map each lab section to the students in that section whose group is larger than size 4. Assume there is always at least one student in each section whose group size is larger than 4. public Map<Integer, List<Student>> grpMap(List<List<Student>> lst) { return lst.stream() .map(o -> o.stream() .filter(getGroup.size() > 4) .collect(Collectors.toList())) .collect(Collectors.groupingBy( o -> o.get(0).getLabSection())); } 3. Each TA submits a list of their students. Write a method that will get the number of students who are over age 20. public int over20 (List<List<Student>> lst) { return lst.stream() .map(o-> o.stream() .f
자주 묻는 질문
이 문서는 무료인가요?
네. “Ôn tập lập trình Java (MT2 Review Solutions) - Ching and Christines” 문서는 무료입니다. 로그인 후 '다운로드'를 클릭하여 원본 파일을 받으세요.
이 문서는 몇 페이지로 되어 있나요?
이 문서는 11페이지입니다, Lập trình Java 과정용. 다운로드하기 전에 온라인으로 미리 볼 수 있습니다.
다운로드하기 전에 미리 볼 수 있나요?
네. 이 페이지의 온라인 리더를 통해 문서를 미리 본 후 다운로드 여부를 결정할 수 있습니다.
Ôn tập lập trình Java (MT2 Review Solutions) - Ching and Christines
미리보기 생성 중...
Trích nội dung tài liệu
Midterm 2 Review Solutions Streams Intermediate Operations to Know 1. stream(): Converts a collection into a stream 2. sorted(Comparator c): Sorts the stream using c, which can also be a lambda 3. map(Function f)(): Applies f to each element in the stream 4. filter(Predicate p): Tests each element with p to see if it should remain in the stream Terminal Operations to Know 1. reduce(BinaryOperator accumulator): Applies the accumulator and combines the elements in the stream, two at a time. Returns an Optional. 2. collect(Collector c): Turns the stream into a collection. To a List: Collectors.toList() To a Set: Collectors.toSet() To a Map: Collectors.grooupingBy(Function f) 3. forEach(Consumer action) Practice Problems Given the following classes, write methods to perform the desired operations. You may only use one semicolon per method. public class Student { public int getLabSection() { ... } public int getAge() {...} public Group getGroup {...} } public class Group { public int size() {...} public Group merge(Group other) { ... } } 1 1. Collect all the unique lab sections from a list of students. There should not be duplicates. public Collection<Integer> uniqueSections(List<Student> lst) { return lst.stream() .map(Student::getLabSection) .collect(Collectors.toSet()); } 2. Each TA submits a list of their students. Write a method that will map each lab section to the students in that section whose group is larger than size 4. Assume there is always at least one student in each section whose group size is larger than 4. public Map<Integer, List<Student>> grpMap(List<List<Student>> lst) { return lst.stream() .map(o -> o.stream() .filter(getGroup.size() > 4) .collect(Collectors.toList())) .collect(Collectors.groupingBy( o -> o.get(0).getLabSection())); } 3. Each TA submits a list of their students. Write a method that will get the number of students who are over age 20. public int over20 (List<List<Student>> lst) { return lst.stream() .map(o-> o.stream() .f
- 문서명
- Ôn tập lập trình Java (MT2 Review Solutions) - Ching and Christines
- 학교 / 강의
- University of California, Berkeley · Lập trình Java
- 내용
- Tài liệu ôn tập giữa kỳ về lập trình Java, bao gồm các bài tập thực hành về streams và iterators.
- 목차
- 이 문서는 명확한 목차가 없습니다.
- 페이지 수
- 11 페이지
- 업로더
- Uni24h
댓글 (0)
댓글이 없습니다. 첫 댓글을 남겨보세요!
Asymptotics II, Search Trees (Discussion 7) (Kỹ thuật phân tích thời gian chạy, cây tìm kiếm nhị phân) - Christine Zhou
Introduction to Java (Discussion 1) (Giới thiệu về Java) - Christine Zhou
More Sorting (Discussion 13) (Thuật toán sắp xếp nâng cao) - Christine Zhou
O, b, j, e, c, t, s (Discussion 3) (Lập trình hướng đối tượng trong Java) - Christine Zhou
Giáo trình Lập trình Java
Tổng hợp Đề Toán 5 - Luyện thi vào Lớp 6 - CLB EMath
Bài giảng vật lý đại cương (Chương 3) - Đỗ Ngọc Uấn
Chương 8.Nguyên tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 7.Cơ học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang
Chương 6.Quang học lượng tử - Vật lý đại cương 3 - TS.Nguyễn Thị Trang

댓글 (0)
댓글이 없습니다. 첫 댓글을 남겨보세요!