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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:42:29+00:00 2026-06-18T14:42:29+00:00

I have a Map as below – ConcurrentHashMap<Long, AtomicLong> histogram = new ConcurrentHashMap<Long, AtomicLong>();

  • 0

I have a Map as below –

ConcurrentHashMap<Long, AtomicLong> histogram = new ConcurrentHashMap<Long, AtomicLong>();

This map contains lot of key value pair. Putting the AtomicLong as the value was necessary so that is the reason I have put like that in that map.

So now if I am trying to iterate through ConcurrentHashMap that I mentioned above, it always give me error on this line-

buckets[i] += histogram.get(time);

as- The operator += is undefined for the argument type(s) int, AtomicLong

I am not sure how can I fix this problem? I cannot go back and change the data structure to all Integer instead of Long and AtomicLong.

So I need to find out how to make change in the below code so that it starts working. I was thinking of casting to Integer. But it was also not working.

Below is my code

private static void logHistogramInfo() {

    System.out.println("From Main Thread: " + histogram);

    int[] definition = { 0, 20, 40, 60, 80, 100 };
    int[] buckets = new int[definition.length];

    for (Long time : histogram.keySet()) {
        for (int i = definition.length - 1; i >= 0; i--) {
            if (time >= definition[i]) {
                      //error on the below line
                buckets[i] += histogram.get(time);
                break;
            }
        }
    }
    for (int i = 0; i < definition.length; i++) {
        String period = "";
        if (i == definition.length - 1) {
            period = "greater than " + definition[i] + "ms";
        } else {
            period = "between " + (definition[i] + 1) + " and " + definition[i + 1] + "ms";
        }
        System.out.println(buckets[i] + " came back " + period);
    }

}
  • 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-18T14:42:30+00:00Added an answer on June 18, 2026 at 2:42 pm

    The += operator was originally intended for use with the primitive data types (int, long…). Since these cannot be put in a map, the wrapper classes exists. When you use an Integer or Long with any arithmetic operator, these are automatically “unboxed” to their corresponding primitive type.

    However, there is no primitive type corresponding to any AtomicXYZ. You can, however, use any of the methods the Number class provides to get its value as a primitive, e.g. longValue() or intValue(). Note that the value of your atomic long can in principle be larger than the largest int (or Integer), so you may want to deal with the potential overflow in some way.

    [edit] Or you can use the get() method as assylias points out (which I was not aware of as I never used the atomic types before), which does the same thing as longValue() for AtomicLong (and the same thing as intValue() for AtomicInteger), as can be seen from its implementation.

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

Sidebar

Related Questions

I have a map like this as shown below... Key Value 23 20 32
I have a ConcurrentHashMap in the below format: ConcurrentHashMap<String,ConcurrentHashMap<String,ArrayList>> Now in this map,I want
I have a Map of Lists with key = GROUP and value = List
I have a hash map table as below, HashMap<String, String> backUpCurency_values = new HashMap<String,
I have map with key and value and my goal is to get list
I have a hash map as below HashMap<String, String> map = new HashMap<String, String>();
I have a class like the one below: class Foo { private: std::map<std::string, Bar*>
I want to Display Google Map into my wordpress site. I have used below
I have image map that can I move, but this map will be so
I have a map containing boost::function values, as defined below: std::map <std::string, boost::function<std::string (std::string,

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.