find vowels in string java code example
Example 1: count vowels in a string java
int count = 0;
String sentence = "My name is DEATHVADER, Hello World!!! XD";
char[] vowels = {'a', 'e', 'i', 'o', 'u'};
for (char vowel : vowels)
for (char letter : sentence.toLowerCase().toCharArray())
if (letter == vowel) count++;
System.out.println("Number of vowels in the given sentence is " + count);
Example 2: java program to print vowels in a string
String str = "hello";
String vowels = "aeiou";
for(char c : str) if(vowels.contains(c)) System.out.print(c + "");