Count number of words in string example java program code
import java.util.HashMap; public class RunApplication { public static void main(String[] args) { String sentence = "this is that is not is"; // Split sentence in word String[] words = sentence.split(" "); System.out.println("Total Word used in sentence is " + words.length); HashMap<String, Integer> wordCounter = new HashMap<String, Integer>(); for (String w : words) { //Search for word w boolean foundStatus = wordCounter.containsKey(w); if (foundStatus) { //if found than ...