Search Header Logo

Java 8 Lambda & Streams

Authored by Pawan G

Other

Professional Development

Used 1+ times

Java 8 Lambda & Streams
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

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)

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?