Here you can find the source of normalizeWhiteSpace(String str)
public static String normalizeWhiteSpace(String str)
//package com.java2s; //License from project: Open Source License import java.text.Normalizer; public class Main { public static final String SPACE = " "; public static String normalizeWhiteSpace(String str) { if (str == null) { return null; }//from w ww.jav a 2 s . c om String normalized = Normalizer.normalize(str, java.text.Normalizer.Form.NFD); int len = normalized.length(); StringBuffer sb = new StringBuffer(); int spaceCount = 0; for (int i = 0; i < len;) { int codePoint = normalized.codePointAt(i); boolean whitespace = Character.isWhitespace(codePoint); boolean space = Character.isSpaceChar(codePoint); int offset = Character.charCount(codePoint); i += offset; if (space || whitespace) { spaceCount++; if (spaceCount == 1) { sb.append(SPACE); } } else { spaceCount = 0; char[] chars = Character.toChars(codePoint); sb.append(chars); } } String result = sb.toString().trim(); return Normalizer.normalize(result, java.text.Normalizer.Form.NFC); } public static String trim(String str) { return str == null ? null : str.trim(); } }