Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6740807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:39:01+00:00 2026-05-26T11:39:01+00:00

I need to sort a Jsoup Elements container by its ownText(). What is a

  • 0

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>>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:39:02+00:00Added an answer on May 26, 2026 at 11:39 am

    The Jsoup Elements already implements Collection, it’s essentially a List<Element>, so you don’t need to convert it at all. You just have to write a custom Comparator<Element> for Element because it doesn’t implement Comparable<Element> (that’s why you’re seeing this compile error).

    Kickoff example:

    String html ="<p>one</p><p>two</p><p>three</p><p>four</p><p>five</p>";
    Document document = Jsoup.parse(html);
    Elements paragraphs = document.select("p");
    
    Collections.sort(paragraphs, new Comparator<Element>() {
        @Override
        public int compare(Element e1, Element e2) {
            return e1.ownText().compareTo(e2.ownText());
        }
    });
    
    System.out.println(paragraphs);
    

    Result:

    <p>five</p>
    <p>four</p>
    <p>one</p>
    <p>three</p>
    <p>two</p>
    

    See also:

    • Sorting an ArrayList of Contacts based on name?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview and I need to sort its elements when the user
I have an array which i need to sort its elements by occurrence then
I need to sort an example XML in a way that all the ShippingPoints
I need some sort of node-graph editor, that hopefully works on both Mac and
I need to sort an array that can look like this: $array[4][0] = array('id'
I have an array of filenames and need to sort that array by the
I need a sort of live effect on some checkbox - I need that
I have an ArrayList which I need to sort and also I need a
I need to sort the nodes of a directed graph such that the number
i need to sort a large XML file and i've been reading that placing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.