One more cool method I discovered quite recently thanks to one question posted on the Groovy Community Slack. Groovy String API has one handy yet straightforward method - count(charSequence) . This method allows you to quickly discover how many occurrences of the given characters sequence exist in the input string. You can count single letters, as well as substrings, in a pretty efficient way.

groovy:000> "Lorem ipsum dolor sit amet".count("o") ===> 3 groovy:000> "Lorem ipsum dolor sit amet".count("or") ===> 2 groovy:000> "Lorem ipsum dolor sit amet".count("abc") ===> 0

Groovy Tutorial | Useful String Methods | #groovylang In this video, I show you useful Groovy string methods you may haven't hear about. Enjoy! Watch now 6:03

Thank you!

Thank you so much for reading up to this point! I hope this article met your expectations, and you have learned something valuable from it. If you have one more minute, leave me a comment below, please. This way, I can thank you for your time more in person.

And last but not least. If you find this blog post valuable, help me spread the word, please. You can share it on Twitter, LinkedIn, or anywhere else you can think of. This single tweet or post on social media helps a lot. One more time - thank you so much! You’re awesome!