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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:35:08+00:00 2026-05-22T19:35:08+00:00

I have an ArrayList of String[] . Each String[] contains two values: value and

  • 0

I have an ArrayList of String[].

Each String[] contains two values: value and date.

If I print it, it will look something like this:

 value | date
-------|----------
 357.0 | 2011/05/30
-234.0 | 2011/05/31
-123.0 | 2011/05/30

i want to make a new ArrayList, where all values in same date are summed. Like this:

 value | date
-------|----------
 234.0 | 2011/05/30
-234.0 | 2011/05/31

Can anyone help?

  • 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-22T19:35:09+00:00Added an answer on May 22, 2026 at 7:35 pm

    You too, are suffering from object denial.

    String is not a good type for handling numbers or dates. For a number I’d use int (if you only have integer values), double or BigDecimal (if it’s a monetary ammount or some other exact decimal number).

    For the date I’d use either a Date/Calendar or LocalDate from Joda Time (if you can use an external library).

    Obviously this means that you can no longer store your data in a String[], but that’s not really an appropriate type for any kind of structured data, anyway.

    You’d want to write a class that reflects what your values are about:

    public class DatedValue {
      private final Date date;
      private final BigDecimal value;
    
      public DatedValue(final Date date, final BigDecimal value) {
        this.date = date;
        this.value = value;
      }
    
      public Date getDate() {
        return date;
      }
    
      public BigDecimal getValue() {
        return value;
      }
    }
    

    Then you can simply create the new values by iterating over the original ArrayList<DatedValue>:

    Map<Date,DatedValue> result = new LinkedHashMap<Date,DatedValue>();
    for(DatedValue dv : datedValues) {
      DatedValue newDV = result.get(dv.getDate());
      if (newDV == null) {
        newDV = dv;
      } else {
        newDV = new DatedValue(dv.getDate(), dv.getValue().add(newDV.getValue()));
      }
      result.put(dv.getDate(), newDV);
    }
    List<DatedValue> sums = new ArrayList<DatedValue>(result.values());
    
    • 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 where each object contains a string 'word' and
I have an ArrayList of HashMap . Each HashMap contains many key-value-pairs. I want
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
I have an arraylist that contains items called Room. Each Room has a roomtype
I have an arraylist that gets different type of values in it, 1st value->
I have set up a HashMap like so: Map<String, ArrayList<String>> theAccused = new HashMap<String,
Hi have a arraylist of String and it contains bunch of numbers and I
I think most coders have used code like the following : ArrayList<String> myStringList =
I currently have a custom listview where each item on the list contains two
I have an ArrayList<String> , and I want to remove repeated strings from it.

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.