xxxxxxxxxx
System.out.print("Vowels in the given String are:");
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o'
|| str.charAt(i) == 'u') {
System.out.print(" " + str.charAt(i));
}
}
xxxxxxxxxx
String str = "hello";
//Java 8
HashSet<Character> vowels = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
//Java 9+
Set<Character> vowels = Set.of('a', 'e', 'i', 'o', 'u');
for(char c : str) if(vowels.contains(c)) System.out.println(c + "");