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

  • SEARCH
  • Home
  • 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 7430185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:05:54+00:00 2026-05-29T09:05:54+00:00

I have Java bean class and I want to sort list of these beans

  • 0

I have Java bean class and I want to sort list of these beans by one bean attribute that is of String type. How can I do that?

  • 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-29T09:05:55+00:00Added an answer on May 29, 2026 at 9:05 am

    Either make the type itself implement Comparable<Foo>, implementing the compareTo method by comparing the two strings, or implement a Comparator<Foo> which again compares by the strings.

    With the first approach, you’d then just be able to use Collections.sort() directly; with the second you’d use Collections.sort(collection, new FooComparator());

    For example:

    public class Foo {
        public String getBar() {
            ...
        }
    }
    
    public class FooComparatorByBar implements Comparator<Foo> {
        public int compare(Foo x, Foo y) {
            // TODO: Handle null values of x, y, x.getBar() and y.getBar(),
            // and consider non-ordinal orderings.
            return x.getBar().compareTo(y.getBar());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bean that i want to inject with a named list using
Say I have the following simple java bean: class MyBean { private Date startDate;
I have Java Map (out of Strings and Ints) objects that I want to
I have a bunch of java custom tags that use spring managed beans.. since
I have initialized a java.util.logging.Logger bean and now want to add a Handler which
I have a single java bean, which is already annotated for JPA, that I
I have a String that I'm autowiring as a bean. The value for the
I want to have java script clicking a link on the page..I found something
I have a class that must be initialized with an absolute pathname. The thing
On my Tomcat-Spring-Java project I want to have the following URLS /index - to

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.