Here you can find the source of findElementsByTag(Element element, String... tags)
public static Elements findElementsByTag(Element element, String... tags)
//package com.java2s; /**/* w w w . jav a 2 s .co m*/ * Copyright (C) 2012-2014 Gist Labs, LLC. (http://gistlabs.com) * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; public class Main { /** Returns the all elements matching any of the given tags (case-insensitive). */ public static Elements findElementsByTag(Element element, String... tags) { List<Element> results = new ArrayList<Element>(); Set<String> tagSet = new HashSet<String>(); for (String tag : tags) tagSet.add(tag.toLowerCase()); filterElementsByTag(results, element, tagSet); return new Elements(results); } private static void filterElementsByTag(List<Element> results, Element element, Set<String> tagSet) { if (tagSet.contains(element.tag().getName().toLowerCase())) results.add(element); for (Element child : element.children()) filterElementsByTag(results, child, tagSet); } }