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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:15:08+00:00 2026-06-01T03:15:08+00:00

i am having a bean class like public class ItemBean{ String item_id, item_title, image_url,

  • 0

i am having a bean class like

public class ItemBean{
    String item_id, item_title, image_url, link_url, description, publish_date,
        in_app_date, sub_section_id, type, duration, orig_url, sync;
    public ItemBean() {  ....  }
    ....
    ....
}

now in activity, i am getting values of itemBeans and making list;
to use in comparator. You can see my code;

public void sortDate() {
    List<ItemBean> listIB = new ArrayList<ItemBean>();
    for(int i=0; i<DispLibActivity.itemListVect.size(); i++)
    {
        listIB.add(DispLibActivity.itemListVect.get(i));
    }
    //      Sorting  Call
    Collections.sort(listIB, ItemSimpleListActivity.compareDate);
    itemBeans = new ItemBean[listIB.size()];
    for (int i=0; i<listIB.size(); i++)
    {
        itemBeans[i] = listIB.get(i);
        System.out.println("Date: "+itemBeans[i].publish_date);
    }
}

My Comparator

public static Comparator<ItemBean> compareDate = new Comparator<ItemBean>() {
    public int compare(ItemBean one, ItemBean other) {
        return one.publish_date.compareTo(other.publish_date);
    }
}

But, i am getting sorted collection as following :-
Date: 1-1-2009 08:00:00 CST
Date: 10-1-2011 08:00:00 CST
Date: 10-1-2011 08:00:00 CST
Date: 12-2-2010 08:00:00 CST
Date: 4-1-2009 08:00:00 CST
Date: 4-18-2011 08:00:00 CST
Date: 4-6-2010 08:00:00 CST
Date: 4-6-2010 08:00:00 CST
Date: 9-20-2011 08:00:00 CST
Date: 9-20-2011 08:00:00 CST
Date: 9-20-2011 08:00:00 CST

Which is not proper sorting order.

Can anyone tell me the alternate ways or what is the bug with this code?

  • 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-01T03:15:10+00:00Added an answer on June 1, 2026 at 3:15 am

    You have to compare dates and not strings (publish_date). So in method compare() you parse the String date into a Date object (e.g. via SimpleDateFormat) and compare those two dates via Date.compareTo

    • 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 looks like this Class Person{ private String name; private
I have a class that is something like the following: public class Foo {
I have two bean Code: public class ApplContactDtl { ....... And Code: public class
In spring you can initialize a bean by having the applicationContext.xml invoke a constructor,
I'm having an issue with pulling a Spring bean from an application context. When
I am having some trouble accessing a stateful session bean (SFSB) from an application
Let's suppose I have a widget class: struct Widget { public Color Color {
I would like to use @Repository spring annotation to avoid adding bean in context.xml.
Let's say I have a fairly large IList<foo> where foo looks like this: public
I've got a model that looks like class order(models.Model): user = models.ForeignKey(some_user) number =

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.