Java Words Count

How To Count Words In A String Using Java Netbeans

words count in java

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.


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:

number of words in a string using java
Result : 11


Share this

Related Posts

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer