Longest Subsequence of a String containing only Consonants | Java program to find the longest subsequence which contain all consonants ; Returns true if x is consonants . ; Function to check whether a character is consonants or not ; Function to find the longest subsequence which contain all consonants ; Driver code ; Function call
class GFG { static boolean isConsonants ( char x ) { x = Character . toLowerCase ( x ) ; return ! ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } static String longestConsonantsSubsequence ( String str ) { String answer = " " ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isConsonants ( str . charAt ( i ) ) ) { answer += str . charAt ( i ) ; } } return answer ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . print ( longestConsonantsSubsequence ( str ) + "NEW_LINE"); } }