Skip to content

Commit 12fa8f8

Browse files
Update CheckVowels.java
Optimized the code by extending the Set elements
1 parent 7a5a9e3 commit 12fa8f8

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/main/java/com/thealgorithms/strings/CheckVowels.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import java.util.Set;
44

5-
/**
6-
* Vowel Count is a system whereby character strings are placed in order based
7-
* on the position of the characters in the conventional ordering of an
8-
* alphabet. Wikipedia: https://en.wikipedia.org/wiki/Alphabetical_order
9-
*/
105
public final class CheckVowels {
11-
private static final Set<Character> VOWELS = Set.of('a', 'e', 'i', 'o', 'u');
6+
7+
private static final Set<Character> VOWELS = Set.of('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');
128

139
private CheckVowels() {
10+
// Private constructor to prevent instantiation
1411
}
1512

1613
/**
@@ -24,7 +21,8 @@ public static boolean hasVowels(String input) {
2421
return false;
2522
}
2623

27-
for (char c : input.toLowerCase().toCharArray()) {
24+
for (int i = 0; i < input.length(); i++) {
25+
char c = input.charAt(i);
2826
if (VOWELS.contains(c)) {
2927
return true;
3028
}

0 commit comments

Comments
 (0)