def title
def author
def isbn
@Override
String toString() {
"$title : $author"
}
}
def books = []
def book1 = new Book(title: "The Curious Gardener", author: "Pavord, Anna", isbn: "1408810069")
def book2 = new Book(title: "Paradise Postponed", author: "Mortimer, John", isbn: "0141193395")
def book3 = new Book(title: "The Sport of Olympic-Style Weightlifting", author: "Miller, Carl", isbn: "0865348111")
books << book1 << book2 << book3
println "Original Book List size >>> "+ books.size()
//edit our list of books to keep only those with the word "The" in the title
books.retainAll {it.title.contains("The")}
println " Book List size >>> "+ books.size()
//edit our list of books to remove any by authors with names beginning with M
books.removeAll {it.author[0] == "P"}
println " Book List size >>> "+ books.size()
println "There are ${books.size()} books left:"
books.each {println it}
Output of Script
[The Sport of Olympic-Style Weightlifting : Miller, Carl] java.util.ArrayList
No comments:
Post a Comment