Skip to content
Iampsp Blog

Iampsp Blog

I am a programming service provider

My Portfolio
Project order
Reviews
Favorite Exchange

Categories

  • C
  • C#
  • C++
  • CSS
  • Firefox Addons
  • Firefox Themes
  • HTML
  • JAVA
  • JavaScript
  • jQuery
  • Mybb Plugins
  • MySQL
  • PHP
  • Python
  • React
  • SQL

Recent Posts

  • jQuery – The noConflict() Method
  • jQuery – AJAX get() and post() Methods
  • jQuery – AJAX load() Method
  • jQuery – AJAX Introduction
  • jQuery Traversing – Filtering

Java How To Count Words

Count Number of Words in a String

You can easily count the number of words in a string with the following example:

Example

String words = "One Two Three Four";
int countWords = words.split("\\s").length;
System.out.println(countWords);

 

Posted on 2025-04-08Author MostafaCategories JAVATags how to count words in java, java, java 17, java 21, java 8 count words in string, java count number of words in a file, java count words in file, java download, java enum, java how to count words in a string, java method to count words in a string, java online compiler, java program to count words, java program to count words in a file, java program to count words in a sentence, java program to count words in a string, java record, java string format, javascript regex

Post navigation

Previous Previous post: Java How To Add Two Numbers
Next Next post: Java How To Reverse a String
Proudly powered by WordPress