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

The Archive Base Latest Questions

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

i have an arraylist of objects, each containing a year/month/day/hour property. what i’m ultimately

  • 0

i have an arraylist of objects, each containing a year/month/day/hour property. what i’m ultimately trying to do, is create a new multidimensional array that contains a group of every object by incrementing hour. so for instance, an example of the final array i’d want is:

array: [0]
            [0] 01:04:00, 4-10-09
            [1] 01:15:00, 4-10-09
       [1]
            [0] 02:25:00, 4-10-09
       [2]
            [0] 06:14:00, 4-10-09
            [1] 06:27:00, 4-10-09
       [3]   
            [0] 04:03:00, 4-11-09
            [1] 04:11:00, 4-11-09

i’m having a difficult time figuring out to properly sort arraylists in java though. how could i sort each section (year,month,day,hour) within the arraylist in ascending order, before inserting them into an final array?

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:38:21+00:00Added an answer on May 13, 2026 at 10:38 am

    To sort a collection you can make a call like this:

    List<MyDate> dates = ... 
    Collections.sort(dates);
    

    The MyDate class will need to implement the interface Comparable which will require the method “int compareTo(object o)” to be implemented.

    In the “compareTo” method, you can then write the code which will call the getters for the year, month, and so on until it figures out whether the current object is less than, equal to or greater than the object “o” being passed into the compareTo method.

    Example:

    public int compareTo(Object o) {
        MyDate otherDate = (MyDate) o;
        int thisYear = this.getYear();
        int otherYear = otherDate.getYear();
        if (thisYear < otherYear) return -1;
        if (thisYear > otherYear) return 1;
        // Now try the month, then day etc
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an arraylist of objects, each containing a unique date in the following
I have an array list of objects in my application. private static ArrayList<Player> userList=new
I have an ArrayList containing Objects that have a date value. Now I want
Possible Duplicate: Sort ArrayList of custom Objects by property I have an arrayList of
I have an ArrayList of Products objects (each one contain attributes like name, image,
I have a problem. I have an ArrayList of objects. Each object contains a
I have an ArrayList of objects where each object contains a string 'word' and
I have an arraylist, that contains model class objects. Here is how I create
I have an ArrayList with custom objects. Each custom object contains a variety of
Say I have an ArrayList of USBDevice Objects. Each USBDevice has ProductID and VendorID

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.