java string count
String line = "Your string here";
String stringToCount = "?";
int count = line.length() - line.replace(stringToCount, "").length();
java string count
String line = "Your string here";
String stringToCount = "?";
int count = line.length() - line.replace(stringToCount, "").length();
how to count words in string in java
String str = "I am happy and why not
and why are you not happy and you should be";
String [] arr = str.split(" ");
Map<String, Integer> map = new HashMap<>();
for (int i=0 ; i < arr.length ; i++){
if (!map.containsKey(arr[i])){
map.put(arr[i],1);
} else{
map.put(arr[i],map.get(arr[i])+1);
}
}
for(Map.Entry<String, Integer> each : map.entrySet()){
System.out.println(each.getKey()+" occures " + each.getValue() + " times");
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us