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

  • Home
  • SEARCH
  • 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 8545715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:51:23+00:00 2026-06-11T12:51:23+00:00

I have a source HashMap in Java: HashMap<String, Integer> keyWordFrequencies; Storing keywords of various

  • 0

I have a source HashMap in Java:

HashMap<String, Integer> keyWordFrequencies;

Storing keywords of various length. I want to traverse this HashMap and work out the lengths of the ngrams stored in the String part of the map which defines the text of each keyword.

With this data, I want to populate a target ArrayList of HashMaps:

ArrayList<HashMap<String, Integer>> keywordNgrams;

With the results, where the index of the ArrayList corresponds to the ngram size of a given keyword minus one, i.e. keywordNGrams(0) will receive the unigrams, keywordNGrams(1) will receive the bigrams and so on. But I’m not sure of the necessary syntax. Traversing the source HashMap is easy enough:

Set keyWordFrequenciesSet = keyWordFrequencies.entrySet();
Iterator keyWordFrequenciesIterator = keyWordFrequenciesSet.iterator();
while(keyWordFrequenciesIterator.hasNext()) {
   Map.Entry m = (Map.Entry) keyWordFrequenciesIteratorIterator.next();
   int ngramLength = String_Utils.getLengthOfNgram(m.getKey().toString());

   Add element to keywordNgrams?

But adding the element to the target ArrayList of HashMap is confusing me. I have tried:

keywordNgrams.add(ngramLength, m);

And various alternatives but to no avail. m should be an element of a HashMap, not a HashMap in itself. Can anyone suggest where I am wrong?

Ideally, I would like to traverse the source HashMap keyWordFrequencies once, and the keywordNgrams ArrayList is initialised to the largest possible ngram size to start with.

  • 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-11T12:51:24+00:00Added an answer on June 11, 2026 at 12:51 pm

    Since you know the greatest ngram-size, I recommend prepopulating keywordNgrams:

    List<Map<String, Integer>> keywordNgrams =
        new ArrayList<Map<String, Integer>>();
    for(int i = 0; i < 5; ++i)
        keywordNgrams.add(new HashMap<String, Integer>());
    

    Then you can write:

    for(final String keyword : keyWordFrequencies.keySet())
        keywordNgrams.get(String_Utils.getLengthOfNgram(keyword) - 1)
                .put(keyword, keyWordFrequencies.get(keyword));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three source files in a folder. I simply want to compile them
I have the following code: HashMap<String, String> hm = new HashMap<String, String>(); hm.put(title, testTitle);
I have source array, and I want to generate new array from the source
I have source for Webapplication in one machine. Developed with VS2010. On this machine
I have this managed bean based on this tutorial . import java.io.Serializable; import javax.enterprise.context.SessionScoped;
I have source XMLfiles that come in with multiple root elements and there is
Have a source xml document that uses namespace containing prefixes and a default namespace.
I have following source. In insertMessage(..), it calls selectMessage to check whether duplicate record
I have a source file, openpage.pl, where I call use_module/1 to import SWI-Prolog's http_open/3:
I have a source XML file that is used to create C# files that

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.