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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:26:57+00:00 2026-05-26T13:26:57+00:00

I haven’t done Java in a while and i need some suggestions and idea’s

  • 0

I haven’t done Java in a while and i need some suggestions and idea’s regarding data structures.

Currently i am using a TreeMap to map String values to Integer value. I now need to do some calculations and divide the Integer value of the map entry by the the size of the whole map and store this for each entry. I was thinking about using a Map,Integer> but is there a 3 way generics data structure in Java?

My current solution for this is this ..

            int treeSize = occurrence.size();
            String [][] weight = new String[treeSize][2];
            int counter=0;
            double score =0;
            for(Entry<String, Integer> entry : occurrence.entrySet()) {
                weight[counter][0]=entry.getKey();
                score=entry.getValue()/treeSize;
                weight[counter][1]= Double.toString(score);
                counter++;
              }
  • 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-26T13:26:57+00:00Added an answer on May 26, 2026 at 1:26 pm

    I would use another object to hold this data:

    public Data {
        private int value;
        private double score;
    
        ...
    }
    

    And then type the map as Map<String, Data>. After inserting all the values, you can iterate over the values and update the ratio property for each value in the map. For example:

    double size = myMap.size();
    for(Map.Entry<String, Data> entry : myMap.entrySet()) {
        Data data = entry.getValue();
        data.setScore(data.getValue() / size); 
    }
    

    EDIT

    Another thought just came to mind. Instead of calculating the values after you have inserted it, you should probably calculate it as you are inserting it; it’s more efficient that way. Of course, you can only do this if you know the total number of values beforehand.

    An even better way is to perform the calculation only when you retrieve a value from the map. There are two advantages to this:

    • You don’t need a separate object. Just abstract the access of the value from the map inside another function which returns the value associated with the key, divided by the size of the map.
    • Since you don’t have a separate object to maintain the calculated value, you don’t need to update it every time you add or delete a new value.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Haven't done ASP.NET development since VS 2003, so I'd like to save some time
Haven't used C++ in a while. I've been depending on my Java compiler to
I haven't done C++ in a while and can't figure out why following doesn't
I have thousands of HTML files to process using Groovy/Java and I need to
I haven't done a lot of .NET programming, but I've examined a few of
I haven't done a lot of work with multi-level, pure CSS drop-down menus before,
I haven't found any documentation on this or seen this done before, but is
Haven't done as much of Javascript as I should have done. I am trying
haven't used regex replaces much and am not sure if how I have done
I haven't worked with Java in about 10 years, so it's very probable I'm

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.