How to count a specific char from a String in Java

H

To count a specific char from a String, you can simply use the Spring framework.

import org.springframework.util.StringUtils;

int occurance = StringUtils.countOccurrencesOf("012405802569015014", "0"); //returns 5
int occurance = StringUtils.countOccurrencesOf("hello world", "l"); //returns 3

Add comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tag Cloud

Categories