Here you can find the source of findNextElementSibling(final Element startElement, final Predicate
static Optional<Element> findNextElementSibling(final Element startElement, final Predicate<Element> condition)
//package com.java2s; //License from project: Open Source License import java.util.Optional; import java.util.function.Predicate; import org.jsoup.nodes.Element; public class Main { static Optional<Element> findNextElementSibling(final Element startElement, final Predicate<Element> condition) { for (Element el = startElement.nextElementSibling(); el != null; el = el.nextElementSibling()) { if (condition.test(el)) { return Optional.of(el); }//from w w w. j av a 2 s.c om } return Optional.empty(); } }