Skip to content
Home
About us
Quizzes
Practice Tests
o
o
o
o
o
o
IS5103 Lesson-10
Mark
August 12, 2024
IS5103
1.Which of the following throw an exception when an Optional is empty?
Each correct answer represents a complete solution. Choose all that apply.
This study source was downloaded by 100000903174213 from CourseHero.com on 01-12-2026 11:46:44 GMT -06:00
https://www.coursehero.com/file/250925558/Quiz-10docx/
, A) opt.orElseThrow();
opt.orElseThrow(RuntimeException::new);
opt.get();
2.Assume that the directory /animals exists and is empty. What is the
result of executing the following code?
Path path = Path.of(“/animals”);
try (var z = Files.walk(path)) {
boolean b = z
.filter((p,a) -> a.isDirectory() && !path.equals(p)) // x
.findFirst().isPresent(); // y
System.out.print(b ? “No Sub”: “Has Sub”);
}
A) The code will not compile because of line x.
3.What could be the output of the following code snippet?
var stream = Stream.iterate(“”, (s) -> s + “1”);
System.out.println(stream.limit(2).map(x -> x + “2”));
A) java.util.stream.ReferencePipeline$3@4517d9a3
4.What could be the output of the following?
Predicate <String>predicate = s -> s.startsWith(“g”);
var stream1 = Stream.generate(() -> “growl!”);
var stream2 = Stream.generate(() -> “growl!”);
var b1 = stream1.anyMatch(predicate);
var b2 = stream2.allMatch(predicate);
System.out.println(b1 + ” ” + b2);
A) The code hangs.
5.What could be the output of the following?
Predicate predicate = s -> s.length()> 3;
var stream = Stream.iterate(“-“,
s -> ! s.isEmpty(), (s) -> s + s);
var b1 = stream.noneMatch(predicate);
var b2 = stream.anyMatch(predicate);
System.out.println(b1 + ” ” + b2);
A) An exception is thrown
6.Which are true statements about terminal operations in a stream that
runs successfully?
Each correct answer represents a complete solution. Choose all that
apply
This study source was downloaded by 100000903174213 from CourseHero.com on 01-12-2026 11:46:44 GMT -06:00
https://www.coursehero.com/file/250925558/Quiz-10docx/
Home
About us
Quizzes
Practice Tests
o
o
o
o
o
o
IS5103 Lesson-10
Mark
August 12, 2024
IS5103
1.Which of the following throw an exception when an Optional is empty?
Each correct answer represents a complete solution. Choose all that apply.
This study source was downloaded by 100000903174213 from CourseHero.com on 01-12-2026 11:46:44 GMT -06:00
https://www.coursehero.com/file/250925558/Quiz-10docx/
, A) opt.orElseThrow();
opt.orElseThrow(RuntimeException::new);
opt.get();
2.Assume that the directory /animals exists and is empty. What is the
result of executing the following code?
Path path = Path.of(“/animals”);
try (var z = Files.walk(path)) {
boolean b = z
.filter((p,a) -> a.isDirectory() && !path.equals(p)) // x
.findFirst().isPresent(); // y
System.out.print(b ? “No Sub”: “Has Sub”);
}
A) The code will not compile because of line x.
3.What could be the output of the following code snippet?
var stream = Stream.iterate(“”, (s) -> s + “1”);
System.out.println(stream.limit(2).map(x -> x + “2”));
A) java.util.stream.ReferencePipeline$3@4517d9a3
4.What could be the output of the following?
Predicate <String>predicate = s -> s.startsWith(“g”);
var stream1 = Stream.generate(() -> “growl!”);
var stream2 = Stream.generate(() -> “growl!”);
var b1 = stream1.anyMatch(predicate);
var b2 = stream2.allMatch(predicate);
System.out.println(b1 + ” ” + b2);
A) The code hangs.
5.What could be the output of the following?
Predicate predicate = s -> s.length()> 3;
var stream = Stream.iterate(“-“,
s -> ! s.isEmpty(), (s) -> s + s);
var b1 = stream.noneMatch(predicate);
var b2 = stream.anyMatch(predicate);
System.out.println(b1 + ” ” + b2);
A) An exception is thrown
6.Which are true statements about terminal operations in a stream that
runs successfully?
Each correct answer represents a complete solution. Choose all that
apply
This study source was downloaded by 100000903174213 from CourseHero.com on 01-12-2026 11:46:44 GMT -06:00
https://www.coursehero.com/file/250925558/Quiz-10docx/