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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:36:21+00:00 2026-05-13T15:36:21+00:00

well, I have an ArrayList with this values ACU ACU ACU ACU ACY ACY

  • 0

well, I have an ArrayList with this values

ACU
ACU
ACU
ACU
ACY
ACY
AER
AER
AER
AGC

I need to get the number of items of each Word, so for

  • ACU we will get 4,
  • ACY we will get 2,
  • AER we will get 3,
  • AGC we will get 1.

Generally the number a word is repeated is a variable
so another time ACU could be 1,and ACY could be 100..

So., I have a class to keep the values “whatWord” AND “howMany”

public class Word {

private String whatWord;
private int howMany;

public  cVOPlaza(String whatWord, int  howMany){
  this.whatWord = whatWord;
  this.howMany= howMany;     
}

public String getwhatWord() {
  return whatWord;
}

public void setwhatWord(String whatWord) {
   this.whatWord = whatWord;
}

public int gethowMany() {
   return howMany;
 }

public void sethowMany(int howMany) {
   this.howMany = howMany;
 } 
}

I am stuck here, because I know the part get(i+1) in the following code will cause error, You know value does not exist, but then I dont know what to do…

ArrayList<Word> arrayWords = new ArrayList<Word>();
 int cuantos = 0;
     for (int i=0;i<OriginalList.size();i++) {
     String word1  = OriginalList.get(i).getWord();
     String word2 = OriginalList.get(i+1).getWord();
             if (word1.equals(word2)){
                       //this counter is bad here... 
                       //where do i increment it??
         howMany++;
         Word a = new Word(word1,howMany);
         ///....DONT KNOW WHERE TO ADD THE OBJECT 
                        //to the list
                         //arrayWords.add(a)
      }
        }

It is supposed that after the for code I will get

ACU 4,
ACY 2,
AER 3,
AGC 1.

First I tried to do a HashMap try, please help me with this code:

 HashMap table = new HashMap();
    int value=0;
    String key=null;

   //INITIALIZE HASH??? LIKE THIS
    for (int i = 0; i < OriginalList.size; i++) {
        table.put(0,OriginalList.get(i).getWord());      
    }


         String word1=null;
         ArrayList<Word> arrayWords = new ArrayList<Word>();
         //LOOP FOR SEARCHING
         for (int i = 0; i < OriginalList.size(); i++) {
               key = OriginalList.get(i).getWord();
               if (table.containsKey(key)) { 
                       word1 = (String) table.get(key);
                       value++;
               }else {
                      word1 = (String) table.get(key);
                      value=1
               }
             //Add result??
             Word a = new Word(word1,value);
         }

Thanks in advance.

  • 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-13T15:36:21+00:00Added an answer on May 13, 2026 at 3:36 pm

    That might be overkill for what you want to do. You could more simply create a map that has the three-letter string as the key and the count as the value. Then just iterate over your ArrayList:

    Map<String, Integer>wordCount = new HashMap<String, int>();
    for(String seq : yourWordList){
        // increment the count of the word by first obtaining its count,
        // and then incrementing it. Paranthesis for clarity
        wordCount.put(seq, (wordCount.get(seq)) + 1);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well i have this messages table with sample values like these: msg_id recipient_id read
Well I have this MySQL stored procedure that I wrote and if I run
I have several input and option elements on my page, each (well almost) have
Well I have a main Screen with 5 buttons. Each time a press a
So let's say I have an ArrayList full of Products that need to be
I have ran through this tutorial a couple times and tried to get an
I have the following code which uses nested for-each loops to traverse two ArrayList
Well I have been stumped as to the best way to do this, I
I have a number of gpx files that my app creates and will need
I have an ArrayList<Double> , the values of which are converted into slices of

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.