forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckVowels.java
More file actions
34 lines (30 loc) · 993 Bytes
/
CheckVowels.java
File metadata and controls
34 lines (30 loc) · 993 Bytes
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
package com.thealgorithms.strings;
import java.util.Arrays;
import java.util.HashSet;
import java.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
*/
public class CheckVowels {
private static final Set<Character> VOWELS = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
/**
* Check if a string is has vowels or not
*
* @param input a string
* @return {@code true} if given string has vowels, otherwise {@code false}
*/
public static boolean hasVowels(String input) {
if (input == null) {
return false;
}
input = input.toLowerCase();
for (int i = 0; i < input.length(); i++) {
if (VOWELS.contains(input.charAt(i))) {
return true;
}
}
return false;
}
}