I want to remove the extra spaces without using a regular expression. I'm using two while loops.
How can this become better / more elegant?
String str = "Hola caracola ";
char[] src = str.toCharArray(), dest = new char[src.length];
int i = 0, j = 0;
while (i < src.length - 1) {
while (i < src.length - 1 && src[i] == ' ' && src[i + 1] == ' ') {
i++;
}
dest[j++] = src[i++];
}
System.out.println(new String(dest, 0, j));