Oracle
1Z0-829 · Question #12
1Z0-829 Question #12: Real Exam Question with Answer & Explanation
Sign in or unlock 1Z0-829 to reveal the answer and full explanation for question #12. The question stem and answer options stay visible for context.
Working with Arrays and Collections
Question
Given the code fragment:
class Book {
String author;
String title;
Book(String authorname, String title) {
this.author = authorname;
this.title = title;
}
}
class SortBook {
public static void main(String[] args) {
List<Book> books = List.of(
new Book("A1", "T1"), new Book("A2", "T2"), new Book("A1", "T2")); // Line n1
books.sort((Book a, Book b) -> a.title.compareTo(b.title)); // Line n2
System.out.println(books);
}
}
Which action sorts the book list?
Options
- AAt Line n2, replace books.sort() with books.stream().sort().
- BAt Line n1, convert books type to mutable ArrayList type.
- CAt Line n1, convert type to mutable array type.
- DAt Line n2, replace compareTo() with compare().
Unlock 1Z0-829 to see the answer
You've previewed enough free 1Z0-829 questions. Unlock 1Z0-829 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.
Topics
#Collections#Lambda Expressions#Immutable Lists#Comparators