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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:49:18+00:00 2026-06-12T15:49:18+00:00

Friends I am having a String that contains date-record String date=10-Oct-2012 @12-Oct-2012 @$12-Oct-2012 @12-Oct-2012

  • 0

Friends I am having a String that contains date-record

String date=10-Oct-2012 @12-Oct-2012 @$12-Oct-2012 @12-Oct-2012 @$12-Sept-2012 13:50@12-Oct-2012 13:50@$12-Feb-2012 13:50@12-Oct-2012 13:50@$

List<Date> myList=new ArrayList<Date>() ;

I need to compare the dates 10-Oct-2012,12-OCt-2012,12-Sept-2012,12-Feb-2012 ie every odd date such that I can arrange them in a chronological order.I am confused on this implementation, please provide me with guidance/hint to solve the problem.

In this case the solution after chronological order would be 12-Feb-2012 @12-Oct-2012 @12-Sept-2012 @12-Oct-2012 @$10-Oct-2012 @12-Oct-2012 @$12-Oct-2012 @12-Oct-2012

Friends,to solve the problem I have created a Hashmap where I am planning to save the first date as key and the entire String as value.

String[] tokens=date.split("\\$");
    demo[0]=demo[0].replaceAll("-", ".");
if(tokens.length>0)
        {
            for(int iTmp=tokens.length-1;iTmp>=0;iTmp--)
            {
                String []demo = tokens[iTmp].split("\\@");
                    demo[0] = demo[0].replace("Jan", "1")
                    .replace("Feb", "2").replace("March","3").replace("April","4").replace("May","5").replace("Jun","6").replace("July","7").replace("Aug","8")
                    .replace("Sept","9").replace("Oct","10").replace("Nov","11").replace("Dec","12");
                    demo[0]=demo[0]+" 00:05:00";
                    Date date1 = null;
                    SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yy");


                    try {
                        date1 = (Date)formatter.parse(demo[0]);

                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    myList.add(date1);
                    System.out.println("ADDED DATE IS"+date1);
                    //System.out.println("KEY VALUE PAIRS  "+key+"  "+tokens[iTmp]);
                }
            }
            System.out.println("READING LISTs");
            for(int iTmp=0;iTmp<myList.size();iTmp++)
            {

                System.out.println(myList.get(iTmp));
            }
            Collections.sort(myList);
            System.out.println("After Sorting");
            for(int iTmp=0;iTmp<myList.size();iTmp++)
            {

                System.out.println(myList.get(iTmp));
                System.out.println();
            } 
  • 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-12T15:49:20+00:00Added an answer on June 12, 2026 at 3:49 pm

    It sounds pretty simple to me:

    • Parse each value into a more suitable type (Calendar, Date, Joda Time’s LocalDate)
    • Sort in natural order

    (Using Joda Time is the preferred option here IMO, as neither Calendar nor Date really represent “just a date”; you’d have to put all values into the same time zone etc.)

    I would definitely not recommend trying to compare them as strings. As usual, convert your data into the most appropriate type for the information it’s trying to represent as early as possible – and convert it into serializing representations (e.g. for storage, propagation to a web service etc) as late as possible.

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

Sidebar

Related Questions

Friends, My school project is having an xml data file: <patients> <patient> <regNo>2012/Mar/003</regNo> <name>Jhon</name>
Dear Friends from Stackoverflow, Please help me with a problem that i'm having when
I'm working on a friends list type function that will display a user's friends
I just created an iPhone app and am having friends try it out, but
hello friends i am having two frames, each frame has a html form which
I'm having a puzzle contest with my friends, and I'm stuck on this problem:
My friends were having discussion on nested lists of objects in LINQ and when
I'm new to Lua programming, having come over from python to basically make a
I am populating a list of friends using an ajax call to a php
I've been creating a node_add function, that works properly to me, but I'm having

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.