Store the generated permutations into the resultant arraylist
ArrayList < String > Res = new ArrayList < > ( ) ; for ( String val : prevResult ) { for ( int i = 0 ; i <= val . length ( ) ; i ++ ) { Res . add ( val . substring ( 0 , i ) + ch + val . substring ( i ) ) ; } }