Try debugging your code by making the method calls separately and printing out the values or the variables as they are executed. You must not be using the methods correctly. By doing each step by itself and examining the results you will see what you are doing wrong.
String str1 = source.replace("aa", "q");
// here print out str1 and source