Answers for "count the occurrences of a character in a string in java using scanner"

1

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);
Posted by: Guest on June-17-2020

Code answers related to "count the occurrences of a character in a string in java using scanner"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language