Print all subsequences of a string | Java program to generate power set in lexicographic order . ; str : Stores input string n : Length of str . curr : Stores current permutation index : Index in current permutation , curr ; base case ; backtracking ; Generates power set in lexicographic order . ; Driver code
class GFG { static void printSubSeqRec ( String str , int n , int index , String curr ) { if ( index == n ) { return ; } if ( curr != null && ! curr . trim ( ) . isEmpty ( ) ) { System . out . println ( curr ) ; } for ( int i = index + 1 ; i < n ; i ++ ) { curr += str . charAt ( i ) ; printSubSeqRec ( str , n , i , curr ) ; curr = curr . substring ( 0 , curr . length ( ) - 1 ) ; } } static void printSubSeq ( String str ) { int index = - 1 ; String curr = " " ; printSubSeqRec ( str , str . length ( ) , index , curr ) ; } public static void main ( String [ ] args ) { String str = " cab " ; printSubSeq ( str ) ; } }