(int x, int y) -> x + y(x, y) -> {return x + y;}(int x, int y) { x + y; }x, y -> x + ymapfilterreduceforEachmap method do in the Streams API?
collect(Collectors.toList())toList()stream()filter()mapfilterreduceterminatefinalClassName::methodNamemethodName.ClassNamemethodName(ClassName)ClassName-methodNameClassName::methodNameobjectName::methodNamesuper::methodNamemethod::objectNameSystem.out::println work in Java 8?
System class.ClassName::newnew ClassName()ClassName.methodName::ClassNamejavaCopy codeList<String> names = Arrays.asList("Anna", "John", "Emma");
names.stream().filter(name -> name.startsWith("E")).collect(Collectors.toList());
sqlCopy code- a) Collects all names
- b) Collects names starting with "A"
- c) Collects names starting with "E"
- d) Collects only empty names
23. What does Optional in Java 8 help with? – a) Handling null values – b) Replacing arrays – c) Managing exceptions – d) Iterating over collections
reduceOptionalmapnoneMatchfilterfindFirstreducemapjava.timejava.datejava.calendarjava.datetimejava.concurrentCompletableFutureThreadLocalConcurrentModificationCollectors.toMap() in Streams API is used to:
Collectors.groupingBy()?
| Qno | Answer |
|---|---|
| 1 | a) (int x, int y) -> x + y |
| 2 | a) Functional |
| 3 | c) Lambda expressions simplify syntax for anonymous functions. |
| 4 | b) An interface with a single abstract method |
| 5 | a) Predicate |
| 6 | c) It provides a way to process collections of objects in a functional style. |
| 7 | b) filter |
| 8 | b) Applies a function to each element and returns a new stream |
| 9 | a) collect(Collectors.toList()) |
| 10 | c) reduce |
| 11 | b) Default |
| 12 | a) To allow interfaces to be backward compatible |
| 13 | a) Yes |
| 14 | c) static |
| 15 | b) They provide utility functions related to the interface. |
| 16 | a) ClassName::methodName |
| 17 | b) objectName::methodName |
| 18 | b) It references an instance method for printing. |
| 19 | a) ClassName::new |
| 20 | a) Anonymous inner classes |
| 21 | b) They allow for functional-style processing of data collections. |
| 22 | c) Collects names starting with “E” |
| 23 | a) Handling null values |
| 24 | b) Optional |
| 25 | b) findFirst |
| 26 | a) java.time |
| 27 | b) CompletableFuture |
| 28 | b) Serialization |
| 29 | c) Convert a stream into a map |
| 30 | a) Group elements based on a classifier function |