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

Java 8 Lambda & Streams

Quiz
•
Other
•
Professional Development
•
Hard

Pawan G
Used 1+ times
FREE Resource
Student preview

9 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
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
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
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
What is the output of the following code snippet?
List<String> names = Arrays.asList("Alice", "Bob", "Charlie", "David");.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
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
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
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
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
Which of the following is a new feature introduced in Java 8 for interfaces?
Default methods
Static methods
Private methods
All of the above
Popular Resources on Wayground
25 questions
Equations of Circles

Quiz
•
10th - 11th Grade
30 questions
Week 5 Memory Builder 1 (Multiplication and Division Facts)

Quiz
•
9th Grade
33 questions
Unit 3 Summative - Summer School: Immune System

Quiz
•
10th Grade
10 questions
Writing and Identifying Ratios Practice

Quiz
•
5th - 6th Grade
36 questions
Prime and Composite Numbers

Quiz
•
5th Grade
14 questions
Exterior and Interior angles of Polygons

Quiz
•
8th Grade
37 questions
Camp Re-cap Week 1 (no regression)

Quiz
•
9th - 12th Grade
46 questions
Biology Semester 1 Review

Quiz
•
10th Grade