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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:12:29+00:00 2026-06-02T02:12:29+00:00

I am writing a code for displaying time vs size. I am using a

  • 0

I am writing a code for displaying time vs size.
I am using a hashmap to make entries.The problem is that it do the calculations correctly but in the end when i try to print out the hashmap ,it does not display all the results for 7 minutes.Instead it displays the result of last entry 7 times.I have tried a lot to figure out the problem but couldn’t.Plzz help me out

Here is my code

public class Analysis
{
    public static class KeepTime
    {
        String time;
        long TotalSize;
    }

    Main f1 = new Main();
    public static int j = 0;
    public static int check = 0;
    public HashMap<String, KeepTime> hMap_time = new HashMap<String, KeepTime>();
    public KeepTime TimerInstance = new KeepTime();

    void TimeBasedReporting()
    {
        String skey;
        String key;
        int k;
        int y;

        for (k = 1; k <= f1.Flows().size(); k++)
        {
            check = 0;
            j = 0;

            skey = Integer.toString(k);

            if (hMap_time.isEmpty())
            {
                //some code
                key = Integer.toString(hMap_time.size() + 1);
                hMap_time.put(key, TimerInstance);
                j = 1;
            }
            else if (check == 0 && j == 0)
            {
                for (y = 1; y <= hMap_time.size(); y++)
                {
                    //some code
                    }
                }
            }

            if (check == 0 && j == 0)
            {
                // some code
                key = Integer.toString(hMap_time.size() + 1);
                hMap_time.put(key, TimerInstance);
            }
            else
            {}


        }



    }
}

Following is the output

          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
          03:08:39,AM  424
  • 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-02T02:12:30+00:00Added an answer on June 2, 2026 at 2:12 am

    You’re creating a single instance of KeepTime and using a reference to that object as the value in various key/value pairs.

    You should be creating a new instance each time you add a new entry, if you want them to be independent. (And yes, I agree with the comment that you almost certainly don’t want a map here – but you’d get the same problem if you added the same reference to a list multiple times, too.)

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

Sidebar

Related Questions

While writing code in a file that would comprise of PHP, HTML, CSS &
I am writing code to clone object but have no cue from Hobo documentation.
I'm writing code in PHP that requires including a config.php file depending on the
I'm writing an Android app that communicates with a website. Any time I hit
I'm writing an app that sets an alarm, and here's the relevant code that's
I'm writing an Android app in Eclipse, and displaying some text on screen using
When writing code, I often place debug messages in the code. The debug messages
While writing code, it is pretty common to request a page with an appended
When writing code in an Eclipse project, I'm usually quite messy and undisciplined in
I'm writing code to import dozens of moderate sized text files into SQL SERVER

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.