Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Sorting date using BeanComparator

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Thanked 0 Times in 0 Posts

    Default Sorting date using BeanComparator

    I am new to this forum. I want to sort dates according to date,month and year using BeanComparator. My code is like this. But it will sort based on date without considering month and year.

    Please help me out to solve this problem
    public static Comparator enquiryDateCompare=new Comparator(){
    		public int compare(Object bean1, Object bean2){
    			SimpleDateFormat newDate1=new SimpleDateFormat("yyyy-mm-dd");
    			SimpleDateFormat newDate2=new SimpleDateFormat("yyyy-mm-dd");
    			Date date1;
    			Date date2;
    				return date1.compareTo(date2);
    			}catch(java.text.ParseException ex){
    				System.out.println("Exception "+ex);
    			return 0;			
    Last edited by copeg; April 12th, 2011 at 08:55 AM.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 827 Times in 770 Posts
    Blog Entries

    Default Re: Sorting date using BeanComparator

    I'm not sure I understand the problem (sorting by dates works for me). I recommend you post an SSCCE that clearly demonstrates the problem (and please use the code tags when doing so), describing the behavior you want vs the behavior you see.

    Edit: and please don't double post. Your other post has been deleted.
    Last edited by copeg; April 12th, 2011 at 08:59 AM.

Similar Threads

  1. Editing a date
    By waterjames in forum Java Theory & Questions
    Replies: 0
    Last Post: November 27th, 2010, 01:00 PM
  2. Calendar date
    By joshft91 in forum Object Oriented Programming
    Replies: 11
    Last Post: November 6th, 2010, 02:47 AM
  3. DATE.java!
    By hiimjoey11 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 3rd, 2010, 05:37 PM
  4. Declaring a date
    By Akim827 in forum Java Theory & Questions
    Replies: 7
    Last Post: October 12th, 2010, 11:47 AM
  5. How to set expiry date for cms?
    By khodam in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: December 4th, 2009, 12:15 PM