- Notifications
You must be signed in to change notification settings - Fork 19.9k
/
Copy pathCheckVowels.java
34 lines (29 loc) · 968 Bytes
/
CheckVowels.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
packagecom.thealgorithms.strings;
importjava.util.Set;
/**
* Vowel Count is a system whereby character strings are placed in order based
* on the position of the characters in the conventional ordering of an
* alphabet. Wikipedia: https://en.wikipedia.org/wiki/Alphabetical_order
*/
publicfinalclassCheckVowels {
privatestaticfinalSet<Character> VOWELS = Set.of('a', 'e', 'i', 'o', 'u');
privateCheckVowels() {
}
/**
* Checks if a string contains any vowels.
*
* @param input a string to check
* @return {@code true} if the given string contains at least one vowel, otherwise {@code false}
*/
publicstaticbooleanhasVowels(Stringinput) {
if (input == null || input.isEmpty()) {
returnfalse;
}
for (charc : input.toLowerCase().toCharArray()) {
if (VOWELS.contains(c)) {
returntrue;
}
}
returnfalse;
}
}