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
  • Gaming
  • HTML
  • JAVA
  • JavaScript
  • jQuery
  • Mybb Plugins
  • MySQL
  • PHP
  • Python
  • React
  • SQL
  • Web Services
  • XML

Recent Posts

  • Top 6 Best Minecraft Server Hosting Options in 2025
  • Top 15 Most Popular Google Doodle Games in 2025
  • Top 11 IRC Clients for Windows, macOS, and Linux in 2025
  • Top 10 Open Source Video Games in 2025
  • Top 10 Free Image Hosting Services for 2025

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