code: public static String shrink(String string, char c) {
  		if (string == null) {
  			return null;
  		}
  		string = string.trim();
  		Pattern pattern = Pattern.compile("\\" + String.valueOf(c) + "{2,}");
  		return pattern.matcher(string).replaceAll(String.valueOf(c));
  	}
docs: Trims the string and replaces runs of whitespace with a single character.