Java 如何在lambda中执行If或操作

Java 如何在lambda中执行If或操作,java,lambda,Java,Lambda,我把书的所有信息都放到一个列表中,并用关键字过滤它们 List<Book> books = bookService.getAllBooks(); List<Book> filteredBooks = books.stream().filter(b-> b.getName().contains(keyword) || b.getDescription().contains(keyword)) List books=bookService.getAllBooks()

我把书的所有信息都放到一个列表中,并用关键字过滤它们

List<Book> books = bookService.getAllBooks();

List<Book> filteredBooks = books.stream().filter(b-> b.getName().contains(keyword) || b.getDescription().contains(keyword))
List books=bookService.getAllBooks();
List filteredBooks=books.stream().filter(b->b.getName().contains(关键字)| | b.getDescription().contains(关键字))
但是,
b.getDescription()
可以返回null,所以我得到了null指针异常

如何在筛选器中执行类似
b.getName()或IF!b、 getDescription().isEmpty b.getDescription()

使用:

List<Book> filteredBooks = books.stream()
                                .filter(b-> b.getName().contains(keyword) ||
                                            (b.getDescription() != null && b.getDescription().contains(keyword)));
List filteredBooks=books.stream()
.filter(b->b.getName().contains(关键字)||
(b.getDescription()!=null和&b.getDescription().contains(关键字));

try
b.getDescription()!=null&&b.getDescription().contains(关键字)
@YCF\u L:大致相同,IMHO:)我猜是的,thabk