Affichage des articles dont le libellé est java string. Afficher tous les articles
Affichage des articles dont le libellé est java string. Afficher tous les articles

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


JAVA - Some Java String Functions

JAVA - Some Java String Functions

JAVA - Some Java String Functions

____________________________________________________________________

In this java Tutorial we will see Some String Methode In Java NetBeans .

Source Code:

package JavaDB_001;

public class Project {

public static void main(String[] args){
 String str = "1bestcsharp.blogspot.com";

 System.out.println("length: "+str.length());
 System.out.println("indexOf: "+str.indexOf("."));
 System.out.println("lastIndexOf: "+str.lastIndexOf("."));
 System.out.println("startsWith: "+str.startsWith("1"));
 System.out.println("endsWith: "+str.endsWith("m"));
 System.out.println("compareTo: "+str.compareTo("1bestcsharp"));
 System.out.println("compareTo: "+str.compareTo("1bestcsharp.blogspot.com"));
 System.out.println("compareTo: "+str.compareTo("www.1bestcsharp.blogspot.com"));
 System.out.println("equals"+str.equals(new String("1bestcsharp")));
 System.out.println("toUpperCase: "+str.toUpperCase());
 System.out.println("toLowerCase: "+str.toLowerCase());
 System.out.println("trim: "+new String("        1bestcsharp.blogspot.com").trim());
 System.out.println("replace: "+str.replace("com", "net"));
}

}
/////// OUTPUT:
length: 24
indexOf: 11
lastIndexOf: 20
startsWith: true
endsWith: true
compareTo: 13
compareTo: 0
compareTo: -70
equalsfalse
toUpperCase: 1BESTCSHARP.BLOGSPOT.COM
toLowerCase: 1bestcsharp.blogspot.com
trim: 1bestcsharp.blogspot.com
replace: 1bestcsharp.blogspot.net