code: static int collapse(char[] chars, int len) {
  		// collapse
  		// After the processing implied by replace, contiguous sequences of
  		// #x20's are collapsed to a single #x20, and leading and trailing
  		// #x20's are removed.
  		replace(chars, len);
  
  		int newLen = len;
  
  		// contiguous sequences of #x20's are collapsed to a single #x20
  		if (newLen > 1) {
  			int i = 0;
  			while (i < (newLen - 1)) {
  				char thisChar = chars[i];
  				char nextChar = chars[i + 1];
  				if (thisChar == ' ' && nextChar == ' ') {
  					// eliminate one space
  					shiftLeft(chars, i, newLen - i);
  					newLen--;
  				} else {
  					i++;
  				}
  			}
  		}
  
  		// leading and trailing #x20's are removed
  		newLen = trimSpaces(chars, newLen);
  
  		return newLen;
  	}
docs: returns new length