Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.List; import java.util.ArrayList; public class BookSortDemo2 { public static void main(String[] args) { // create three Book objects Book b1 = new Book(9999999999, Clowning

import java.util.List; import java.util.ArrayList;

public class BookSortDemo2 { public static void main(String[] args) { // create three Book objects Book b1 = new Book("9999999999", "Clowning Around", "Joe King"); Book b2 = new Book("2222222222", "Travel With Me", "Sandy Beach"); Book b3 = new Book("4444444444", "Interior Design", "Anita Room"); // create an empty list of books List bookList = new ArrayList<>(); // add the three Book ojects bookList.add(b1); bookList.add(b2); bookList.add(b3); // display list before and after sorting System.out.println("***COMPARATOR DEMO***"); System.out.println(" Before Sort "+bookList); // sort list using sort method of List and a Comparator implementation using lambda bookList.sort((book1,book2) -> {return book1.getAuthor().compareTo(book2.getAuthor());}); System.out.println(" After Author sort "+ bookList); } }

Rewrite the lambda expression in the BookSortDemo2 program so that it still sorts the list based on authors but in reverse order.

Thank you

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago