Hello,
How can i create a new array list "onlyRF", and here to print only the books with genre Romance and Fiction, from the array list "books"?
List<Book> books = new ArrayList<>();
AudioBook book = new AudioBook ("Harry Potter", "Joan Rowling",LiteratureGenre.Romance,Locale.ENGLISH,LocalDate.of(2000, 7, 8),
"reader1",LocalTime.of(1, 25), 0);
AudioBook book1 = new AudioBook ("Inky heart", "Cornelia Funke",LiteratureGenre.Poetry, Locale.UK,LocalDate.of(1965, 12, 5),
"reader2",LocalTime.of(1, 10), 7);
AudioBook book2 = new AudioBook ("Don Quixote", " Miguel de Cervantes",LiteratureGenre.Romance, Locale.FRENCH,LocalDate.of(1605, 4, 12),
"reader2",LocalTime.of(4, 25), 0);
Book b1 = new Book("Alisa in Wonderland","Charles Dodgson",LiteratureGenre.Fiction, Locale.GERMAN, LocalDate.of(2019, 1, 1));
Book b2 = new Book("Dune", "Frank Herbet",LiteratureGenre.Romance,Locale.ITALIAN, LocalDate.of(2020, 4, 1));
What I have tried:
List<Book> onlyRF = new ArrayList<>();
for (Book b:books) {
if(b.getBookGenre().equals(book)) {
System.out.println(b);
}
}