I need to sort a Jsoup Elements container by its ownText(). What is a recommended way to accomplish that?
Does convertinng it to an ArrayList first for use with a custom comparator make sense?
BTW, I tried sorting it directly, as in Collections.sort(anElementsList) but the compiler complains:
Bound mismatch: The generic method sort(List<T>) of type Collections is not applicable for
the arguments (Elements). The inferred type Element is not a valid substitute for the
bounded parameter <T extends Comparable<? super T>>
The Jsoup
Elementsalready implementsCollection, it’s essentially aList<Element>, so you don’t need to convert it at all. You just have to write a customComparator<Element>forElementbecause it doesn’t implementComparable<Element>(that’s why you’re seeing this compile error).Kickoff example:
Result:
See also: