Java Lambda Expressions and Streams

Last Updated :
Discuss
Comments

Question 1

Which of the following is true about lambda expressions in Java?

  • A

    Lambda expressions can be used to define a method.

  • B

    Lambda expressions are instances of functional interfaces.

  • C

    Lambda expressions cannot access instance variables.

  • D

    Lambda expressions are not supported in Java 8.



Question 2

What is the correct syntax for a lambda expression in Java?



  • A

    (parameter) -> {body}

  • B

    parameter => body

  • C

    parameter -> {body}

  • D

    {parameter} -> body

Question 3

What will the following lambda expression do? x -> x * 2

  • A

    Doubles the value of x

  • B

    Prints the value of x

  • C

    Doubles the value of x and prints it

  • D

    Nothing

Question 4

What does the following code snippet represent? () -> { return 42; }

  • A

    A method reference

  • B

    A functional interface

  • C

    A lambda expression

  • D

    An anonymous class

Question 5

Which of the following functional interfaces can be used with lambda expressions in Java?

  • A

    Runnable

  • B

    Callable

  • C

    Comparator

  • D

    All of the above

Question 6

Which of the following lambda expressions is correct for a function that takes two integers and returns their sum?

  • A

    (a, b) -> a + b

  • B

    a, b -> {return a + b;}

  • C

    (a, b) { return a + b }

  • D

    (a, b) -> a * b

Question 7

Which of these statements correctly describes the Stream API in Java 8?

  • A

    Streams are used to process collections of objects sequentially or in parallel.

  • B

    Streams allow modifying the original data source.

  • C

    Streams are primarily used to create new collections.

  • D

    Streams only allow sequential processing.

Question 8

Which of the following is an intermediate operation in the Stream API?

  • A

    collect()

  • B

    map()

  • C

    forEach()

  • D

    reduce()

Question 9

Which of the following is a terminal operation in the Stream API?

  • A

    map()

  • B

    filter()

  • C

    reduce()

  • D

    flatMap()

Question 10

How can a stream be parallelized in Java?

  • A

    By using stream.parallel()

  • B

    By using stream.parallelize()

  • C

    By using parallelStream()

  • D

    By using stream.split()

There are 13 questions to complete.

Take a part in the ongoing discussion