Java 8 Lambda & Streams

Java 8 Lambda & Streams

Assessment

Quiz

Other

Professional Development

Hard

Created by

Pawan G

Used 1+ times

FREE Resource

Student preview

quiz-placeholder

9 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What is the difference between the Stream.sorted() and Stream.sort() methods in Java 8?

Stream.sorted() returns a new stream with the elements sorted, while Stream.sort() modifies the original stream in place.

Stream.sorted() performs a stable sort, while Stream.sort() performs an unstable sort.

Stream.sorted() accepts a Comparator as an argument, while Stream.sort() does not

There is no difference, they are synonyms.

2.

MULTIPLE SELECT QUESTION

45 sec • 1 pt

  1. What is the purpose of the Stream.distinct() method in Java 8?

To remove duplicate elements from the stream based on their hashcode and equals methods.

To return a stream that contains only the first occurrence of each element in the original stream.

To return a stream that contains only the elements that are different from their adjacent elements in the original stream.

Don't know..

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. What is the result of applying the Stream.count() method to an empty stream in Java 8?

0

1

null

An exception is thrown

4.

MULTIPLE CHOICE QUESTION

1 min • 2 pts

  1. What is the output of the following code snippet?
    List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "David");

    names.stream()

    .filter(name -> name.length() > 4)

    .map(name -> name.toUpperCase())

    .forEach(System.out::println);

ALICE BOB CHARLIE DAVID

ALICE CHARLIE DAVID

BOB CHARLIE DAVID

CHARLIE DAVID

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. Which of the following is not a valid way to create a lambda expression in Java 8?

(int x) -> x * x

x -> x * x

x -> { return x * x; }

(x) -> return x * x;

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. Which of the following is a terminal operation in the Stream API in Java 8?

map

filter

reduce

all of the above

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. Which of the following is a valid way to create a date object in Java 8?

LocalDate date = new LocalDate(2024, 2, 6);

LocalDate date = LocalDate.of(2024, 2, 6);

LocalDate date = LocalDate.parse(“2024-02-06”)

Both b) and c)

8.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. Which of the following is a new feature introduced in Java 8 for handling exceptions?

try-with-resources

multi-catch

lambda expressions

None of the above

9.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

  1. Which of the following is a new feature introduced in Java 8 for interfaces?

Default methods

Static methods

Private methods

All of the above