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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:19:54+00:00 2026-05-27T09:19:54+00:00

For example, I have two objects: Icecream ice1 = new Icecream(vanilla, newDate(11, 09, 09));

  • 0

For example, I have two objects:

Icecream ice1 = new Icecream(vanilla, newDate(11, 09, 09));
Icecream ice2 = new Icecream(choko, newDate(10, 08, 08));
// where first argument is a String and second argument is a Date 

how can I print the out so that they will be ordered by the date starting from earliest? (toStrign method is already configured)

Output sholud be:

Vanilla, 10-08-08
Vanilla, 11-09-09

Thank you!

  • 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-27T09:19:55+00:00Added an answer on May 27, 2026 at 9:19 am

    You can define a natural ordering for your class IceCream by implementing the Comparator interface.

    public class IceCream implements Comparator{
        // ...
        final String name; 
        final Date date;
        public Icecream(String name, Date date){
           this.name = name;
           this.date = date;
        }
        public int compare(Object o1, Object o2) {
            return ((IceCream)o1).date.compareTo(((IceCream)o2).date);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: I have two shared objects (same should apply to .dlls). The first shared
For example, I have two elements in an enum. I would like the first
For example I have two model objects, Person and Address. Address has a reference
Let's say you have two objects (for example, a UITextviews, but it could be
For example, we have two domain objects: Cell and Body (as in human cell
For example i have two classes A and B, such that for two objects
I have (for example) these two objects: class Customer { public int Id {
For example, let's assume that i have two QuerySEt objects: queryset1 = my_model1.objects.all().order_by('-created') queryset2
How would I find a row with two objects? Example: $m = new Mongo();
I have two time objects. Example time.struct_time(tm_year=2010, tm_mon=9, tm_mday=24, tm_hour=19, tm_min=13, tm_sec=37, tm_wday=4, tm_yday=267,

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.