how to count number of words in a string
String name = "Carmen is a fantastic play"; //arbitrary sentence
int numWords = (name.split("\\s+")).length; //split string based on whitespace
//split returns array - find legth of array
System.out.println(numWords);
Also in Java:
- find min in array java
- how to add an image to a gui in java windowbuilder
- how to take input in java
- tolowercase java
- even or odd in java
- java do while
- append to arraylist by index java
- query java persistence
- covariant type in java
- change fragment in android studio
- graal.js pass javascript array to java function
- counting repeated characters in a string in java
- java.sql.SQLException: Before start of result set
- check last character of string java
- what is java plug-in
- working with buttons in applet java
- java int stream min
- sqrt in java
- java get current date without time
- java ternary operator
- 2d array length in java
- sort a map based on keys and values using java 8
- java identifiers
- how timer class and display to jtextfield w3schools in java