How To Count Words In A String Using Java Netbeans
In This Java Tutorial We Will See How To Count The Number Of Words In A jTextField Text Using Java Programming Language And NetBeans Editor.
STEPS:
1 - the user enter text into the jtexfields
2 - the user click "count" button to display the number of words in the text.
STEPS:
1 - the user enter text into the jtexfields
2 - the user click "count" button to display the number of words in the text.
Project Source Code:
private void jButtonCountActionPerformed(java.awt.event.ActionEvent evt) {
String txt = jTextField1.getText();
String[] words = txt.split(Pattern.quote(" "));
System.out.println(words.length);
}
///////////////OUTPUT:
Download Projects Source Code