Method Reference MCQs with answers
78 questions tagged Method Reference, each with the correct answer and an explanation. Page 1 of 4.
- Which method reference would map a collection of strings to their lengths?
- To map a stream of strings to their uppercase form, which method reference is used?
- What method reference would replace `() -> new Employee()`?
- Which is the method reference equivalent of `(a, b) -> a.compareToIgnoreCase(b)`?
- Which method reference is ideal for sorting a list of integers?
- Which method reference helps to instantiate a new ArrayList?
- What functional interface would you use with `String::length` in a stream mapping?
- What method reference could map Employee objects to their ages?
- Which type of method reference is `System.out::println`?
- What is the correct method reference to print each element in a list?
- Which method reference can replace a lambda used in filtering non-empty strings?
- What is the equivalent method reference for `x -> x.toString()`?
- Which method reference would replace `str -> str.trim()`?
- What method reference is appropriate for converting a list of numbers to their absolute values using streams?
- Which functional interface is used with `Supplier<Employee> supplier = Employee::new;`?
- Which type of method reference is `Employee::getName` when used in mapping operations?
- In the real-world, which method reference helps when sorting a list of strings alphabetically?
- What method reference would replace `(e1, e2) -> e1.getName().compareTo(e2.getName())`?
- Which method reference is used to create new objects via Supplier?
- Which method reference is commonly used to print each element of a collection?