Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java program to print vowels in a string

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 + "");
 
PREVIOUS NEXT
Tagged: #java #program #print #vowels #string
ADD COMMENT
Topic
Name
1+5 =