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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:02:18+00:00 2026-06-18T05:02:18+00:00

My program contains algorithms that output text (String). Eventually I want to print out

  • 0

My program contains algorithms that output text (String). Eventually I want to print out the word that occurred the most. But before I do this, I need to store it in a data structure. So I was wondering what data structure is the best (easy and efficient) to store Strings and then be able to obtain the most frequent element? I don’t want to use any libraries. Thanks

  • 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-18T05:02:19+00:00Added an answer on June 18, 2026 at 5:02 am

    I don’t think any data structure does exactly this but here is how I would do it.

    Maintain a Map<String, Integer> of each word to the number of times it was encountered and as you update the map keep track of the string corresponding to the largest number stored. For example:

    String maxWord = null;
    Integer maxCount = -1;
    Map<String, Integer> wordCount = new HashMap<String, Integer>();
    for (String str : getMyProgramOutput()) {
      if (!wordCount.containsKey(str)) { wordCount.put(str, 0); }
      int count = wordCount.get(str) + 1;
      if (count > maxCount) {
        maxWord = str;
        maxCount = count;
      }
      wordCount.put(str, count);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below program contains two show() functions in parent and child classes, but first show()
Upon loading into a C++ program a Prolog program that contains the command 'send'
I have a program with a class that contains a public enum, as follows:
I have a table that contains log entries for a program I'm writing. I'm
in Python, I have created a text generator that acts on certain parameters but
The mini-program is supposed to print out all the possible routes through a maze,
My program contains the following code. pthread_t PThreadTable[32]; for (i=1; i<P; i++) // Checked
My program contains a child of a widget class, and the paint() function is
I am trying to solve a problem. This program contains all the edge in
Let's say I am writing installation script for the program which contains executable file

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.