Change A to B and B to A
for ( int i = 0 ; i < prev . length ( ) ; i ++ ) { if ( prev . charAt ( i ) == ' A ' ) { prev . replace ( prev . charAt ( i ) , ' B ' ) ; } else { prev . replace ( prev . charAt ( i ) , ' A ' ) ; } }