diff --git a/core-java-modules/core-java-string-operations-4/pom.xml b/core-java-modules/core-java-string-operations-4/pom.xml
index 7f71ea8da5..0f1e377d18 100644
--- a/core-java-modules/core-java-string-operations-4/pom.xml
+++ b/core-java-modules/core-java-string-operations-4/pom.xml
@@ -30,6 +30,12 @@
commons-lang3
${apache-commons-lang3.version}
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
diff --git a/core-java-modules/core-java-string-operations-4/src/main/java/com/baeldung/checkvowels/CheckVowels.java b/core-java-modules/core-java-string-operations-4/src/main/java/com/baeldung/checkvowels/CheckVowels.java
new file mode 100644
index 0000000000..fd60427a4e
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-4/src/main/java/com/baeldung/checkvowels/CheckVowels.java
@@ -0,0 +1,38 @@
+package com.baeldung.checkvowels;
+
+import java.util.regex.Pattern;
+
+public class CheckVowels {
+ private static final String VOWELS = "aeiouAEIOU";
+ private static final Pattern VOWELS_PATTERN = Pattern.compile("[aeiou]", Pattern.CASE_INSENSITIVE);
+
+ public static boolean isInVowelsString(char c) {
+ return VOWELS.indexOf(c) != -1;
+ }
+
+ public static boolean isInVowelsString(String c) {
+ return VOWELS.contains(c);
+ }
+
+ public static boolean isVowelBySwitch(char c) {
+ switch (c) {
+ case 'a':
+ case 'e':
+ case 'i':
+ case 'o':
+ case 'u':
+ case 'A':
+ case 'E':
+ case 'I':
+ case 'O':
+ case 'U':
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public static boolean isVowelByRegex(String c) {
+ return VOWELS_PATTERN.matcher(c).matches();
+ }
+}
diff --git a/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/checkvowels/CheckVowelsUnitTest.java b/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/checkvowels/CheckVowelsUnitTest.java
new file mode 100644
index 0000000000..52b0e55692
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-4/src/test/java/com/baeldung/checkvowels/CheckVowelsUnitTest.java
@@ -0,0 +1,51 @@
+package com.baeldung.checkvowels;
+
+import org.junit.jupiter.api.Test;
+
+import static com.baeldung.checkvowels.CheckVowels.*;
+import static org.assertj.core.api.Assertions.*;
+
+class CheckVowelsUnitTest {
+
+ @Test
+ void givenAVowelCharacter_thenInVowelString() {
+ assertThat(isInVowelsString('e')).isTrue();
+ }
+
+ @Test
+ void givenAConsonantCharacter_thenNotInVowelString() {
+ assertThat(isInVowelsString('z')).isFalse();
+ }
+
+ @Test
+ void givenAVowelString_thenInVowelString() {
+ assertThat(isInVowelsString("e")).isTrue();
+ }
+
+ @Test
+ void givenAConsonantString_thenNotInVowelString() {
+ assertThat(isInVowelsString("z")).isFalse();
+ }
+
+ @Test
+ void givenAVowelCharacter_thenInVowelSwitch() {
+ assertThat(isVowelBySwitch('e')).isTrue();
+ }
+
+ @Test
+ void givenAConsonantCharacter_thenNotInVowelSwitch() {
+ assertThat(isVowelBySwitch('z')).isFalse();
+ }
+
+ @Test
+ void givenAVowelString_thenInVowelPattern() {
+ assertThat(isVowelByRegex("e")).isTrue();
+ assertThat(isVowelByRegex("E")).isTrue();
+ }
+
+ @Test
+ void givenAVowelCharacter_thenInVowelPattern() {
+ assertThat(isVowelByRegex(Character.toString('e'))).isTrue();
+ assertThat(isVowelByRegex("E")).isTrue();
+ }
+}