DEV Community

Discussion on: Daily Challenge #219 - Compare Strings

Collapse
 
gabriela profile image
Gabi

Java:
public static int strCount(String str, char letter) {
int count = 0;
for (char element : str.toCharArray()) {
if (element == letter) {
count++;
}
}
return count;
}

Collapse
 
olegthelilfix profile image
Oleg Aleksandrov • Edited
public static int strCount(String str, char letter) {
    return str.chars().filter(it -> it == letter).count();
}
Collapse
 
gabriela profile image
Gabi

Love it!