Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

count occurrences of character in string java 8

String someString = "elephant";
long count = someString.chars().filter(ch -> ch == 'e').count();
assertEquals(2, count);
 
long count2 = someString.codePoints().filter(ch -> ch == 'e').count();
assertEquals(2, count2);
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #count #occurrences #character #string #java
ADD COMMENT
Topic
Name
4+7 =