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 9306485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:11:03+00:00 2026-06-19T00:11:03+00:00

I am working on a report module that shows the time spent and number

  • 0

I am working on a report module that shows the time spent and number of tasks. The values are set in the Java Bean and the bean object is stored in a array.I am using separate queries to get time and number of tasks.Now i have to sort the array based on time and number of tasks.
The code below compares only Strings:

if (!list.isEmpty()) {
    Collections.sort(list, new Comparator<Project>() {
        @Override
        public int compare(Project p1, Project p2) {

            return p1.getName().compare(p2.getName());
        }
       });
   }

I have problems in sorting the integer value of a property in JavaBean which is stored in an array.Any help is greatly appreciated.

  • 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-06-19T00:11:04+00:00Added an answer on June 19, 2026 at 12:11 am

    In your comments below the question you say you have:

    Project[] array = new Project[3];
    

    If I were you I’d declare Project as

    public class Project implements Comparable<Project> {
    
        @Override
        public int compareTo(Project other) {
            return this.id - other.id; // or whatever property you want to sort
        }
    

    Then you can sort your array by simply calling

    Arrays.sort(array);
    

    If you don’t want your class to implement the Comparable interface you can pass a comparator to Arrays.sort():

        Arrays.sort(array, new Comparator<Project>() {
            @Override
            public int compare(Project o1, Project o2) {
                return o1.id - o2.id; // or whatever property you want to sort
            }
        });
    

    I used an anonymous one, you could also extract it to it’s own class if needed elsewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on report that shows the Velocity - vs. Capacity in %
I am working with excel report in Open ERP with report_aeroo module. I want
I have a report working well where I extract the number of logins per
A peer of mine is working on a report that displays the weekly (Sunday
I am currently working with an SSRS 2008 report that returns a dataset similar
I am currently working on a GWT application that requires report printing. The use
I've set up phpUnderControl and it's all working very well, except that for a
I'm working on a report that was made before I started working here and
I'm working on a report in reporting services that has the user select a
I've just updates a working report where I had to change the location of

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.