Check out example codes for "count the number of words in a string java". It will help you in understanding the concepts better.

Code Example 1

public static void main(String[] args)
    { 
        //return the number of words in a string 
        
       String example = "This is a good exercise"; 
       
       int length = example.split(" ").length;
       
       System.out.println("The string is " + length + " words long.");
        
        
    }

Learn ReactJs, React Native from akashmittal.com