Skip to content

Commit e15fc2a

Browse files
committed
replaced count consonants/vowels with a more generic snippet
1 parent 31ec9f8 commit e15fc2a

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Count Character Occurrences
3+
description: Counts the occurrences of the specified characters in a given string
4+
author: Mcbencrafter
5+
tags: string,characters,counter,occurence
6+
---
7+
8+
```java
9+
import java.util.List;
10+
11+
public static int countCharacterOccurrences(String text, List<Character> characters) {
12+
int count = 0;
13+
14+
for (char character : text.toCharArray()) {
15+
if (characters.indexOf(character) == -1)
16+
continue;
17+
18+
count++;
19+
}
20+
21+
return count;
22+
}
23+
24+
// Usage:
25+
System.out.println(countCharacterOccurrences("hello world", List.of('l', 'o'))); // 5
26+
```

snippets/java/string-manipulation/count-consonants.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

snippets/java/string-manipulation/count-vowels.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)