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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:34:52+00:00 2026-05-13T10:34:52+00:00

I created a class DateTime (which wraps GregorianCalendar). I also created a class Event.

  • 0

I created a class DateTime (which wraps GregorianCalendar). I also created a class Event.
I would like to create a collection of events from which I can retrieve an event by its date.
For instance:
event is of type Event;
date1 and date2 are of type DateTime and also date1.equals(date2);
‘events’ is my event collection.

event.put(date1, event)

will add ‘event’ to the collection so that I can retrieve it by

event.get(date2)

I think of using a TreeMap to implement this event collection because I might want to print all the events sorted by date.

So how to set DateTime to be a key of a TreeMap? What should I add to DateTime? and what else to do?
Thanks.

  • 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-13T10:34:52+00:00Added an answer on May 13, 2026 at 10:34 am

    You just need to have the DateTime implement Comparable<DateTime>, something along the lines of:

    class DateTime implements Comparable<DateTime> {
      GregorianCalendar calendar;
    
      ...
    
      public int compareTo(DateTime other) {
        if (calendar.equals(other.calendar))
          return 0;
        else if (calendar.before(other.calendar))
          return -1;
        else
          return 1;
      }
    }
    

    The Comparable interface is documented here.

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

Sidebar

Related Questions

The DateTimeConverter class provides conversions between DateTime and string. I would also like to
I created a class that's something like this: public class MovieTheaterList { public DateTime
I created an overriding formatter which masks some strings like this: class MaskFormatter(logging.Formatter): def
i had created a class with two properties one of datetime datatype and other
I have a model with a datetime field: class MyModel(models.Model): created = models.DateTimeField(auto_now =
Continuing on my attempt to create a DateTime class , I am trying to
I created a class with properties like this public class Dependencies { public string
I created a class (UIView) which has a UIScrollview inside. Through the delegate scrollViewDidEndDecelerating
Here is my custom logger class, which helps me create logs file in my
In a Django application I need to create an order number which looks like:

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.