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

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How we learned to Go in the cloud and not worry about the servers

Business as unusual

Distributed Systems Communication

[NFT Tournament] Recap Stage 3 — AvatarArt Official Launch

Who are Developer Evangelists / Advocates?

Your Workplace Is Affecting Your Mental Health

Set good implementation property in abstract class

Donkey Car — Part 4: Talking to RC Remote

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
Code Factory

Code Factory

More from Medium

Design Patterns — 4

A quick dip of Java — Chapter 1

Aiming for object-oriented design elegance

Mockito