Here you can find the source of normaliseWhitespace(String string)
public static String normaliseWhitespace(String string)
//package com.java2s; //License from project: LGPL public class Main { public static String normaliseWhitespace(String string) { StringBuilder sb = new StringBuilder(string.length()); boolean lastWasWhite = false; boolean modified = false; int l = string.length(); for (int i = 0; i < l; i++) { int c = string.codePointAt(i); if (Character.isWhitespace(c)) { if (lastWasWhite) { modified = true;/*w w w. ja v a2 s .c o m*/ continue; } if (c != ' ') modified = true; sb.append(' '); lastWasWhite = true; } else { sb.appendCodePoint(c); lastWasWhite = false; } } return modified ? sb.toString() : string; } }