Count The Occurrences of a String In Another String | Code Factory

package com.codeFactory;import org.apache.commons.lang3.StringUtils;/**
* @author code.factory
public class CountMatches {
public static void main(String... args) {
System.out.println("\"love\" count : " + StringUtils.countMatches(StringUtils.lowerCase(getText()), "love"));

private static String getText() {
return "Love is a friendship set to music.\n"
+ "The more one judges, the less one love.\n"
+ "Life without love is like a tree without blossoms or fruit.";
"love" count : 3



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store