Write a program to count repeated words in java ?

Java word count program-

In this java pro­gram you will learn how to write a java word count pro­gram. To devel­op this pro­gram you have to fol­low below giv­en steps.

  1. Split the string val­ue using split() method and store it in String array.
  2. Cal­cu­late the size of String array using length method and store it in size Inte­ger vari­able.
  3. Cre­ate a tem­po­rary vari­able of type int and assign default val­ue 1.
  4. Cre­ate out­er for loop and iter­ate till <size vari­able.
  5. Cre­ate inner for loop and start index i+1 and iter­ate till <size vari­able.
  6. Check the con­di­tion if stringSplit[i].equals(stringSplit[j] con­di­tion is true then incre­ment the count vari­able and set ‘0’ in String array for inner loop cur­rent index so that this val­ue will not get count­ed and get matched with oth­er val­ue .
  7. Step 6 will get repeat­ed for each index of out­er for loop, inner loop will get iter­at­ed untill <size.
  8. Once the inner loop exe­cu­tion com­plet­ed we are print­ing index val­ue and its count and set­ting cout val­ue as default val­ue. (Read Also :pro­gram to split inte­ger val­ue in java)

Below is the pro­gram for your ref­er­ence.

Out­put:-