What is the output of the following code? “`java var list = List.of(3, 1, 4, 1, 5); list.stream() .distinct() .sorted() .limit(3) .forEach(System.out::print); “`

Java Professional Hard

Java Professional — Hard

What is the output of the following code? “`java var list = List.of(3, 1, 4, 1, 5); list.stream() .distinct() .sorted() .limit(3) .forEach(System.out::print); “`

Key points

  • The code uses distinct() to remove duplicate elements
  • sorted() arranges the elements in ascending order
  • limit(3) restricts the output to the first 3 elements

Ready to go further?

Related questions