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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:10:03+00:00 2026-06-16T19:10:03+00:00

In my program I have an array list of type Program like this: List<Program>

  • 0

In my program I have an array list of type Program like this:

   List<Program> programList= new ArrayList<Program>(); 

public class Program {

public String name;
public String date;

public Program(String name, String date) {
    this.name = name;
    this.date= date;
}
    public String date getDate()
    {
     return date;
     }

    public String date setDate(String date)
    {
     this.date=date;
     }

      public String date getName()
    {
     return name;
     }

    public String date setName(String name)
    {
     this.name=name;
     }

and in my activity i am adding items to the list

      for(int i=0; i < 100; i++)
      {
       Program p= new Program("name","some date");
       programList.add(p):
      }

And I want to group items by date, like there are hundred items in list and many of them have same date, I want to make pairs with the date and the new lists of the items having same date.

  • 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-16T19:10:04+00:00Added an answer on June 16, 2026 at 7:10 pm

    First of all, your Program class should look like this:

    private String name;
    private String date;
    
    public Program(String name, String date) {
        this.name = name;
        this.date = date;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getDate() {
        return date;
    }
    
    public void setDate(String date) {
        this.date = date;
    }
    

    If you have public fields like you had, its pointless to make getters and setters.

    Anyhow, you could use HashMap for sorting programs by date:

    private static class Bucket {
    
        private List<Program> programs = new ArrayList<Program>();
    
        private static HashMap<String, Bucket> map = new HashMap<String, Bucket>();
    
        public static void addProgram(Program p) {
            String tempDate = p.getDate();
            Bucket correspondingBucket = map.get(tempDate);
            if (correspondingBucket == null) {
                correspondingBucket = new Bucket();
                map.put(tempDate, correspondingBucket);
            }
            correspondingBucket.programs.add(p);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have java API which return this type: ArrayList[ArrayList[String]] = Foo.someJavaMethod() In scala program,
i have a user defined list public class Level2 { public double price {
In my program I have a while loop which iterates through an array list
I have an array of uint-types in C#, After checking if the program is
I have a program that assigns an array beyond it's bounds, and I was
I have a program, which takes a parameter from the args[] array, defined in
I have a small program to do in Java. I have a 2D array
I have a working C program where the length of an array of strings
So I have the following read and write file program for an Array. How
in my program there are three class Student,School and TestStudent. I have declared students

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.