Longest Subsequence of a String containing only vowels | Java program to find the longest subsequence containing only vowels ; Function to check whether a character is vowel or not ; Returns true if x is vowel ; Function to find the longest subsequence which contain all vowels ; Length of the String ; Iterating through the String ; Checking if the character is a vowel or not ; If it is a vowel , then add it to the final String ; Driver code
class GFG { static boolean isVowel ( char x ) { x = Character . toLowerCase ( x ) ; return ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } static String longestVowelSubsequence ( String str ) { String answer = " " ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isVowel ( str . charAt ( i ) ) ) { answer += str . charAt ( i ) ; } } return answer ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . print ( longestVowelSubsequence ( str ) + "NEW_LINE"); } }