Replace two or more spaces with a single space.

Java :

String oldStr = "AAA   BBB";
String newStr = oldStr.replaceAll(" {2,}", " ");

JS :

var oldStr = "AAA   BBB";
var newStr = oldStr.replace(//s{2,}/g," ");

SQL :
If there two records in table A, the s of A2 is "aa bb" and "aaa   bbb".
We can use the like :

UPDATE A SET A2=REGEXP_REPLACE(A2, '( ){2,}', ' '),


and then the new s of A2 is "aa bb" and "aaa bbb".